::: Pro-Business :::
Sunday, September 07, 2008
Links
Minimize
 
A Handy VS.NET Find and Replace Tidbit
Minimize
Location: BlogsBlog    
Posted by: Thomas Goddard 3/18/2007 1:45 PM

If you've ever had to find and replace, you know that it's important to be able to find within strings.  Another less frequently used feature of VS.NET, is to group the find expression and replace the matched string(s) using the variables from the find expression.  To do this in Visual Studio 2005, you find a string such as:

"My string
with some text"

"{[^\"]+}\n{[^\"]+}" - This regular expression finds any string within quotes but not containing quotes [^\”]+, containing a newline \n between any string.  The {} braces provide the grouping functionality required to save the expression groups and use the values in the replace:

"\1\2" - This will fill in the quotes with the two groups from the find and output:

"My string with some text"

I've had to use this at least a few times and it wasn't easy finding the syntax.  Enjoy!

Permalink |  Trackback

Your name:
Title:
Comment:
Add Comment   Cancel 
Contact
Minimize




Cancel   Send
Privacy Statement | Terms Of Use
Copyright (c) 2008 Thomas Goddard | CG Artist, Solutions Architect, Software Developer