there are more that 90+ files(.cs) in my Application.
I have used a statement like
string str = MyMessages.IDS_STR_STRING1;
MyMessages.IDS_STR_STRING2;
MyMessages.IDS_STR_STRING3;
in many files almost say some 40+ files.
Where MyMessages is a static class.
I now have added another function in this class say GetMyString(string identifier). So now the above statmenets would change to
开发者_如何转开发MyMessages.GetMyString("IDS_STR_STRING1");
MyMessages.GetMyString("IDS_STR_STRING2");
MyMessages.GetMyString("IDS_STR_STRING3");
and so on....
Now searching and replacing each statement is tedious and could lead to manual errors. Can i write any macro / a tool that would find the string and replace in the appropriate format ?
You can use the Replace function in Visual Studio which supports regex'es.
Something like:
Input
// search for a whitespace character, then the string 'MyMessages.'
// match the next group of characters that is a word (a-zA-Z) or an _
// and capture it into group number 1
\sMyMessages\.([\w_]+);
Replace
// Replace it with 'MyMessages.GetMyString("', then insert group 1
// then add '");' to the string.
MyMessages.GetMyString("\1");
精彩评论