將所有的"..."字符串替換成_T("..."),但是不能替換#include后面的字符串
由于vs的正則表達式懶惰跟貪婪控制語法不明確,只好用2條表達式來實現
1. 將_T("...")轉換成"..."
_T\x28{"[^"]@"}\x29
\1
2. 將"..."轉換成_T("..."),其中過濾掉#include 的前綴
~(\#include:b){"[^"]@"}
_T(\1)
將兩步合成一個宏,添加到IDE環境中.
Option Strict Off
Option Explicit Off
Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports System.Diagnostics
Public Module RecordingModule
Sub replace_str()
DTE.Windows.Item("{CF2DDC32-8CAD-11D2-9302-005345000000}").Activate() 'Find and Replace
DTE.Find.Action = vsFindAction.vsFindActionReplaceAll
DTE.Find.FindWhat = "_T\x28{""[^""]@""}\x29"
DTE.Find.ReplaceWith = "\1"
DTE.Find.Target = vsFindTarget.vsFindTargetCurrentProject
DTE.Find.MatchCase = False
DTE.Find.MatchWholeWord = False
DTE.Find.MatchInHiddenText = False
DTE.Find.PatternSyntax = vsFindPatternSyntax.vsFindPatternSyntaxRegExpr
DTE.Find.ResultsLocation = vsFindResultsLocation.vsFindResultsNone
DTE.Find.Action = vsFindAction.vsFindActionReplaceAll
DTE.Find.Execute()
DTE.Windows.Item("{CF2DDC32-8CAD-11D2-9302-005345000000}").Activate() 'Find and Replace
DTE.Find.FindWhat = "~(\#include:b){""[^""]@""}"
DTE.Find.ReplaceWith = "_T(\1)"
DTE.Find.Target = vsFindTarget.vsFindTargetCurrentProject
DTE.Find.MatchCase = False
DTE.Find.MatchWholeWord = False
DTE.Find.MatchInHiddenText = False
DTE.Find.PatternSyntax = vsFindPatternSyntax.vsFindPatternSyntaxRegExpr
DTE.Find.ResultsLocation = vsFindResultsLocation.vsFindResultsNone
DTE.Find.Action = vsFindAction.vsFindActionReplaceAll
DTE.Find.Execute()
DTE.Windows.Item("{CF2DDC32-8CAD-11D2-9302-005345000000}").Close()
End Sub
End Module
后續的應用繼續更改上來.
posted on 2009-02-10 18:21
宋振華 閱讀(3366)
評論(2) 編輯 收藏 引用