Reputation: 4048
does anyone know of a tool or extension to Visual Studio 2010 to count non-whitespace (e.g. all characters but not spaces, new lines etc.) for current selection in a document?
Nice to have for code golfing :)
I have a command line tool, but an integrated tool would be very nice. Also I would prefer something to evaluate current selection.
Upvotes: 1
Views: 2392
Reputation: 4048
I finally got to creating this crude macro below by first recording a temporary macro in Visual Studio and then modifying it to look like the below:
Option Strict Off
Option Explicit Off
Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports EnvDTE90a
Imports EnvDTE100
Imports System.Diagnostics
Public Module CountNonWhiteSpaceCharacters
Sub Count()
Dim selection As EnvDTE.TextSelection = DTE.ActiveDocument.Selection()
Dim text As String = selection.Text
text = text.Replace(" ", "")
text = text.Replace(vbCrLf, "")
text = text.Replace(vbTab, "")
MsgBox("Count " + text.Length.ToString())
End Sub
End Module
This can be bound to a keybord shortcut if desired. Otherwise, double clicking it in Macro Explorer will run it.
Upvotes: 2