Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Searching For String Literals

In the quest for localization I need to find all the string literals littered amongst our source code. I was looking for a way to script this into a post-modification source repository check. (I.E. after some one checks something in have a box setup to check this stat) I'll probably use NAnt and CruiseControl or something to handle the management of the CVS (Well StarTeam in my case :( ) But do you know of any scriptable (or command line) utility to accurately cycle through source code looking for string literals? I realize I could do simple string look up based on regular expressions but want a little more bang for my buck. (Maybe analyze the string or put it into categories) Because a lot of times the string may not necessarily require translation. Any ideas?

like image 448
Adam Driscoll Avatar asked Oct 02 '08 20:10

Adam Driscoll


People also ask

What is a literal search string?

A string literal is a programming string in which characters exist as their literal value rather than a variable and appear the same in code and in published material. They are denoted by delimiters. Delimiters are characters, often quotation marks or brackets, that contain a string literal.

What are examples of string literals?

A string literal is a sequence of zero or more characters enclosed within single quotation marks. The following are examples of string literals: 'Hello, world!' 'He said, "Take it or leave it."'

What are string literals in SQL?

A string literal is a sequence of zero or more characters enclosed by single quotes. The null string ( '' ) contains zero characters. A string literal can hold up to 32,767 characters. PL/SQL is case sensitive within string literals.

What is a string literal in Python?

A string literal is where you specify the contents of a string in a program. >>> a = 'A string' Here 'A string' is a string literal. The variable a is a string variable, or, better put in Python, a variable that points to a string. String literals can use single or double quote delimiters.


2 Answers

Visual Studio 2010 and earlier:

  1. Find In Files (CTRL+SHIFT+F)
  2. Use: Regular Expressions
  3. Find: :q (quoted string)
  4. Find All

Find Results window will now contain a report of all files, with line numbers and the line itself with the quoted string.

For Visual Studio 2012 and later search for ((\".+?\")|('.+?')) (reference, hat-tip to @CincauHangus)

like image 175
Duncan Smart Avatar answered Sep 29 '22 23:09

Duncan Smart


It uses the compiled binary instead of source, but Sysinternals' Strings app might be useful.

like image 35
Chris Farmer Avatar answered Sep 29 '22 22:09

Chris Farmer