一般代码编辑器都提供基于正则表达式的查找、替换功能。但支持的标准有所差异,下面举例说明在VS中的实际应用。
Example 1:
source code:

Assert.AreEqual(null, property._AcquiredDate);
Assert.AreEqual(
null, property._AcreageNumber);

aim style:

property._AcquiredDate = null;
property._AcreageNumber 
= null;

Select "Use regular expressions"
Find what: Assert\.AreEqual\({[^,]+}, {[^\)]+}\);
Replace with: \2 = \1;
如果你想反向替换,也就是把上面的结果替换为最上面的代码,这时候,
Find what: {[^:b=]*}:b*=:b*{[^;]*};”,
Replace with: Assert.AreEqual(\2, \1);”。

Example 2:
source code:

<?xml version="1.0" encoding="utf-8"?>
<Topic>
  
<Issue></Issue>
  
<TopicPic></TopicPic>
</Topic>

aim style:

<?xml version="1.0" encoding="utf-8"?>
<Topic>
  
<Issue>{$Issue$}</Issue>
  
<TopicPic>{$TopicPic$}</TopicPic>
</Topic>

Select "Use regular expressions"
Find what: \<{.*}\>\<\/{.*}\>
Replace with: \<\1\>\{\$\1\$\}\<\/\1\>

posted on 2008-03-01 14:34  BlueTzar  阅读(677)  评论(0)    收藏  举报