2010-09-22 32 views
2

在我的應用程序中有超過90個文件(.cs)。C中的字符串或宏#

我用如下語句

string str = MyMessages.IDS_STR_STRING1; 
MyMessages.IDS_STR_STRING2; 
MyMessages.IDS_STR_STRING3; 

在許多文件幾乎可以說一些40+的文件。

其中,MyMessages是一個靜態類。

我現在已經在這個類中添加了另一個函數say GetMyString(string identifier)。 所以現在上面statmenets將變爲

MyMessages.GetMyString("IDS_STR_STRING1"); 
MyMessages.GetMyString("IDS_STR_STRING2"); 
MyMessages.GetMyString("IDS_STR_STRING3"); 

等等....

現在搜索和替換每個語句是乏味的,並可能導致人爲錯誤。 我可以寫任何宏/一個工具,可以找到該字符串,並以適當的格式替換?

回答

5

您可以在Visual Studio中使用支持正則表達式的替換函數。

喜歡的東西:

輸入

// 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 it with 'MyMessages.GetMyString("', then insert group 1 
// then add '");' to the string. 
MyMessages.GetMyString("\1"); 
+0

在GetMystring功能的參數應該是後發現字符串 「」 ...什麼是 – siva 2010-09-22 09:31:57

+0

$ 1的統計MyMessages.GetMyString(「$ 1」); – siva 2010-09-22 09:32:21

+0

你可以查看我的編輯進行澄清 – 2010-09-22 09:39:08