Is there way on visual studio to find and replace text but keeping the number in the string same?
For example, lets say I have a code that saids
fields[0].Value;
fields[1].Value;
And now I would like to replace it with
reader.GetString(0);
reader.GetString(1);
Without manually replacing every single lines of code, I was hoping to do it through find and replace dialog.
Is there any ways of doing this?
Thank you
If you want to replace part of the expression but keep a part (like the number in your case) you can use the search and replace function (ctrl+h) set to use regular expressions (alt+e) and use these expressions:
Search: fields\[(.)\].Value;
Replace: reader.GetString($1);
This will replace all expressions on the form fields[n].Value;
with reader.GetString(n);
where n
is any single character. If you want to restrict it to keep numbers only use fields\[(\d)\].Value;
For more information see: Using Regular Expressions in Visual Studio
I tried it with VS2013 and it worked as expected.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With