Wednesday, January 25, 2006

A VS2005 macro to measure the length of string laterals in the code editor

The following macro, is a Visual Studio macro to measure the length of string laterals in the code editor.

Highlight the string and run the macro, a message box will show the length

Sub MeasureStringLength()
Dim ts AsTextSelection = DTE.ActiveDocument.Selection
Dim msg As String
msg = String.Format("{0}{1}{2} char(s)", ts.Text, ,vbCrLf ts.Text.Length)

MsgBox(msg)

End Sub

How to use
1. Select a string in the Code Editor




2.Run the Macro





3.See the Msessage Box with the length




It is also easy to assign the macro to a custome toolbar button in VS2005, or give it a Keyboard short cut

No comments: