将所有的"..."字符串替换成_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
宋振华 阅读(3329)
评论(2) 编辑 收藏 引用