17 June 2011

Today I've been parsing some text files in Visual Studio 2010 express in a semi-manual kind of way (lots of Find and Replace commands!). They were generally not too bad but I needed to clean them up to bring them into a tool I was writing. Here are some helpful things I worked out along the way:

To remove an empty line, bring up the Find and Replace dialog box (ctrl-h I think) and set the "find what" to
and put in the "replace with" box put
That worked fine for my files though you may want to try something a little more robust if you have tabs and whitespace on the line. First click "use" and set the combo box to "regular expressions". The set "Find what":

and leave "replace with" blank

I also needed to remove brackets along with their contents. Make sure Use Regular Expressions is set, "replace with" is blank and then set "Find words" to:
Then I needed to remove any line that had an apostrophe in it (don't ask why!), so as above, but set the "Find words" to:

Naturally you can replace the apostrophe in the example above with another character, string, or regex substatement.

Need to get red of any lines that contain any non A-Z characters (ie, uppercase only)?
I also cleared out all the numbers from the file. As above but:
And finally removing all whitespace is done using the above settings and then in "Find What" goes:

But that last one is in the shortcut list anyway. Regular Expressions (regex) are definitely something worth learning and not just if you're into programming - I used to use this kind of stuff all the time when I did admin.

Hope you find this helpful. I'm going to try and post a few times a week. Expect some regular updates..!

blog comments powered by Disqus