When you copy code from internet and paste into Visual Studio, have you ever faced the trivial task to remove line numbers in the front of each line of code? I just wrote a macro to do this and I’d like to share it with you.
When we past code into Visual Studio, it often looks like this:
With this macro, we can remove line numbers very quickly. And the following is the script code. It will set the cursor to the start of current opened document, parse the first 3 characters of each line until the end of the document.
Dim objSel As TextSelection = DTE.ActiveDocument.Selection
Dim endLine As Integer = objSel.ActivePoint.Line
For line = 1 To endLine
For bit = 1 To 3
Dim number As Integer
If Integer.TryParse(objSel.Text, number) Then
To use this macro, you can
- Launch Visual Studio
- Press ALT+F8 to open Macro Explorer
- Expand MyMacros node in Macro Explorer
- Right click a module and select ‘New macro’ to create a new macro.
- Past in the script.
And there are several ways to run a macro. They are described in How to: Run Macros. If you find any issue or has any comment, please feel free to let me know