Mark Gilbert's Blog

Science and technology, served light and fluffy.

Time for a little "String Cleaning"

I’ve lost track of the number of times where I’ve copied some text out of Visual Studio, a web page, Word, etc., and wanted to paste just the text – not any of the formatting.  I’ve gotten into the habit of pasting that text data into Textpad to drop all of the formatting first, then recopying the “cleaned” version to the clipboard, and finally pasting in my ultimate target.  It finally dawned on me that there was a better way.

I’ve written a small console app called StringCleaning that automates this cleaning process.  The magic line is as follows:

If (Clipboard.ContainsText) Then Clipboard.SetText(Clipboard.GetText)

The “Clipboard” class is defined as part of System.Windows.Forms.  The above line checks the most recent clipboard entry to make sure it is text, and if so pulls it down as text (which drops the formatting) and then immediately pastes it back to the clipboard (without the formatting).  Incidentally, other than wrapping the above magic line in a Try…Catch block, this is the ONLY line in the application.

Once you have this little application built, you can create a shortcut to it from your desktop or your Quick Launch menu.  I’ve got mine wired up to a SlickRun magic word so that I can run it from the SlickRun command line as follows:

CTRL-C  (copies text)

WINDOWS-Q (opens SlickRun command line)

“clean” – ENTER  (activates my custom magic word)

CTRL-V  (to paste the cleaned text)

My fingers never leave the keyboard and I don’t have any extraneous TextPad windows left open at the end of the process.

Enjoy!

Advertisements

April 7, 2008 - Posted by | Visual Studio/.NET

Sorry, the comment form is closed at this time.

%d bloggers like this: