Visual Studio 查找和替换正则表达式帮助 [英] Visual Studio Find and Replace Regular Expressions help

查看:65
本文介绍了Visual Studio 查找和替换正则表达式帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想替换一些赋值语句,例如:

I'd like to replace some assignment statements like:

int someNum = txtSomeNum.Text; 
int anotherNum = txtAnotherNum.Text;

int someNum = Int32.Parse(txtSomeNum.Text);
int anotherNum = Int32.Parse(txtAnotherNum.Text);

是否有使用正则表达式的 Visual Studio 查找和替换的好方法?我不确定正则表达式是什么.

Is there a good way to do this with Visual Studio's Find and Replace, using Regular Expressions? I'm not sure what the Regular expression would be.

推荐答案

我认为在 Visual Studio 中,您可以用花括号 {txtSomeNum.Text} 标记表达式.然后在替换中,可以用\1来引用.所以替换行将类似于 Int32.Parse(\1).

I think in Visual Studio, you can mark expressions with curly braces {txtSomeNum.Text}. Then in the replacement, you can refer to it with \1. So the replacement line would be something like Int32.Parse(\1).

更新:通过@Timothy003

VS 11 取消了 {} \1 语法并使用 () $1

VS 11 does away with the {} \1 syntax and uses () $1

这篇关于Visual Studio 查找和替换正则表达式帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆