将所有的"..."字符串替换成_T("...")

文章转于:VS正则表达式应用[原创]

将所有的"..."字符串替换成_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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值