随笔-20  评论-12  文章-0  trackbacks-0
将所有的"..."字符串替换成_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 宋振华 阅读(3240) 评论(2)  编辑 收藏 引用

评论:
# re: VS正则表达式应用[原创][未登录] 2009-02-12 13:02 | jans2002
不错哈  回复  更多评论
  
# re: VS正则表达式应用[原创] 2009-02-13 11:24 | 宋震华
谢谢鼓励.  回复  更多评论
  

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理