Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Count distinct strings in C# code

I'm in need to estimate localization effort needed for a legacy project. I'm looking for a tool that I could point at a directory, and it would:

  • Parse all *.cs files in the directory structure
  • Extract all C# string literals from the code
  • Count total number of occurrences of the strings

Do you know any tool that could do that? Writing it would be simple, but if some time can be saved, then why not save it?

like image 274
Marcin Seredynski Avatar asked Apr 07 '11 09:04

Marcin Seredynski


Video Answer


2 Answers

Use ILDASM to decompile your .DLL / .EXE.

I just use options to dump all, and you get an .il file with a section "User String":

User Strings
-------------------------------------------------------
70000001 : (14) L"Starting up..."
7000001f : (12) L"progressBar1"
70000039 : (21) L"$this.BackgroundImage"
70000065 : (10) L"$this.Icon"
7000007b : ( 6) L"Splash"

Now if you want to know how many time a certain string is used. Search for a "ldstr" like this:

IL_003c:  /* 72   | (70)000001       */ ldstr      "Starting up..." /* 70000001 */

I think this will be a lot easier to parse as C#.

like image 184
GvS Avatar answered Sep 28 '22 06:09

GvS


Doing a quick search, I found the following tool that may or may not be useful to you.

http://www.devincook.com/goldparser/

I also found another SO user who was trying to do something similar.

Regex to parse C# source code to find all strings

like image 21
Josh Smeaton Avatar answered Sep 28 '22 07:09

Josh Smeaton