views:

578

answers:

3

Hi,

I'd like to replace some assignment statements like:

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

with

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

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.

+3  A: 

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).

Mark Wilkins
A: 

This is what I was looking for:

Find: = {.*\.Text}

Replace: = Int32.Parse(\1)

David Hodgson
You should escape the second period in the regex.
Max Shawabkeh
Good catch. I actually needed to escape the \ character for it to show.
David Hodgson