將所有的"..."字符串替換成_T("..."),但是不能替換#include后面的字符串
由于vs的正則表達(dá)式懶惰跟貪婪控制語(yǔ)法不明確,只好用2條表達(dá)式來實(shí)現(xiàn)
1. 將_T("...")轉(zhuǎn)換成"..."
_T\x28{"[^"]@"}\x29
\1
2. 將"..."轉(zhuǎn)換成_T("..."),其中過濾掉#include 的前綴
~(\#include:b){"[^"]@"}
_T(\1)
將兩步合成一個(gè)宏,添加到IDE環(huán)境中.
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
后續(xù)的應(yīng)用繼續(xù)更改上來.
posted on 2009-02-10 18:21
宋振華 閱讀(3366)
評(píng)論(2) 編輯 收藏 引用