• VS.net 中,使用正则表达式进行查找、替换


    我们就来看一个具体的实例:
    比如我们有这样一段代码:
                  Assert.AreEqual(null, property._AcquiredDate);
                  Assert.AreEqual(null, property._AcreageNumber);
                  Assert.AreEqual("San Jose", property._City);
                  Assert.AreEqual(null, property._Country);
                  Assert.AreEqual("Santa Clara", property._County);
                  Assert.AreEqual(null, property._DETAILS);
                  Assert.AreEqual("1", property._FinancedNumberOfUnits);
    我们想通过替换的方式,把它变成下面这样的代码:
                  property._AcquiredDate = null;
                  property._AcreageNumber = null;
                  property._City = "San Jose";
                  property._Country = null;
                  property._County = "Santa Clara";
                  property._DETAILS = null;
                  property._FinancedNumberOfUnits = "1";
    这个需求,在写单元测试的时候,会发现经常需要用到。要实现这个功能,我们就可以使用VS.net查询替换功能中的正则表达式.
    在使用选项中选择“正则表达式”,然后
    查找内容为“Assert\.AreEqual\({[^,]+}, {[^\)]+}\);”;
    替换内容为:“\2 = \1;”;
    然后全部替换,OK,我们可以省下大量的时间干其他事情了。
    如果你想反向替换,也就是把上面的结果替换为最上面的代码,这时候,
    查询的内容为:“{[^:b=]*}:b*=:b*{[^;]*};”,
    替换内容为:“Assert.AreEqual(\2, \1);”。
  • 相关阅读:
    redis在centos7下安装(源码编译)
    Centos7之Gcc安装
    Jmeter工具之上传图片,上传音频文件接口
    什么是系统平均负载(Load average)
    sonar+Jenkins 构建代码质量自动化分析平台
    数据库主从相关配置参数说明
    现有数据库配置主从同步
    MySQL5.7多主一从(多源复制)同步配置
    MySQL5.7主从从配置
    MySQL5.7主从同步配置
  • 原文地址:https://www.cnblogs.com/wudingfeng/p/1163444.html
Copyright © 2020-2023  润新知