I am developing a combined Embedded + Desktop application. Memory constraints on the embedded platform make it important to know the size and count of items that will be sent and received. When I make size or element count changes on one system I need to coordinate those changes with the other system.
To get this information, I currently select and copy the elements of interest within visual studio and paste them into an external text editor that can give me the character count and the line count.
I would like to find a way to see that same information (count of selected lines and count of selected characters) within Visual Studio (2017).
The only way I've found so far is to perform find and replace within a selection, which does report the count of replacements. If I use regular expressions for the match I can get a count of whatever matched, so with two passes I can get the count of characters and lines replaced -- but then I have to Ctrl-Z to undo the damage, and this just seems like a bad idea. There must be a better way.
Is there any way to get the count of found or selected elements other than using Find & Replace and then un-doing the damage?
Virtually every other editor I've seen permits doing a "find" within a selection and tells you the count of matches, but I've not found any way to make Visual Studio show the count of matches, even though all the found elements are color-marked. I have to do "replace all" to get the count.
I see that there have been periodic feature requests for this same functionality going back quite a few years, but up to now they have been closed for lack of votes. I found macros for VS2010 that can do this, but I don't find any evidence that macros exist in VS2017. I have not found any marketplace extension that gives the count of selected lines and selected characters.
Note that I'm not looking to count lines of code in a file, or a project, or a solution. I'm only seeking to count the characters and lines "on the fly" in a selection within the Visual Studio IDE. I searched, but did not find any questions that appear to be duplicates of this question.
Edit: Sadly, nearly 4 years later it seems there still is no native way to do this in any version of Visual Studio up to and including VS 2022. VS Code does show the count of selected characters, but that doesn't help since I need the full IDE of Visual Studio. Sigh.
Open a Markdown file and the status bar will display the number of characters (including newlines) present in the file. It will be updated as you type.
We can check all of the lines of code in a file or directory by the command cloc --by-file.
Select the TOOLS menu and then WORD COUNT. A dialogue box will appear containing the character count. Character counting tools many times will provide additional information, such as the character count with and without spaces. In addition, many of the programs will perform a character count of a selected text.
VSCode displays the number of characters currently selected in the status bar, e.g. (143 selected)
You can use the following command (C# language) with my Visual Commander extension to count selected characters and lines:
public class C : VisualCommanderExt.ICommand
{
public void Run(EnvDTE80.DTE2 DTE, Microsoft.VisualStudio.Shell.Package package)
{
EnvDTE.TextSelection ts = DTE.ActiveDocument.Selection as EnvDTE.TextSelection;
System.Windows.MessageBox.Show("Lines=" + (1 + ts.BottomLine - ts.TopLine) + " Characters=" + ts.Text.Length);
}
}
(BTW, Visual Commander can also run a VS 2010 macro.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With