Using the find and replace dialog in Visual Studio (2010) is it possible to replace some text but to preserve the case of the text being replaced.
ie. I want to change 'foo' to 'bar' but in my code I have Foo, foo and FOO. I want the replacement to be Bar, bar, BAR respectively.
Is it possible? I suspect I need to use the regular expression functionality but I need assistance in doing so.
EDIT: I know I can set the match case option, but all that option does is limit the replace to text matching the case of the search term. This is how I am doing it at the moment, but it is tiresome having to do three replacements - foo, Foo and FOO
It is - simply expand the Find Options
area of the Find and Replace
dialog and check the Match Case
checkbox.
Full documentation on the dialog can be found here:
Match case - Only displays instances of the Find what string that are matched both by content and by case. For example, a search for "MyObject" with Match case selected will return "MyObject" but not "myobject" or "MYOBJECT."
Edit: (following clarification)
I don't know of an easy way to do what you want. A RegEx could possibly be constructed that does this, but I suspect that doing 3 search and replace would be faster, easier and less error prone than a RegEx, in this case.
I think if you use "match case" = true then you can replace "Foo" to "Bar" and "foo" to "bar"
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