Say you need to paste a chunk of XML (or WKT) into Visual Studio as a string literal (for your unit tests, or what not). How would you do it?
In C#, string literals can be represented in two ways:
C# supports two forms of string literals: regular string literals and verbatim string literals.
A regular string literal consists of zero or more characters enclosed in double quotes, as in
"hello"
, and may include both simple escape sequences (such as\t
for the tab character) and hexadecimal and Unicode escape sequences.A verbatim string literal consists of an
@
character followed by a double-quote character, zero or more characters, and a closing double-quote character. A simple example is@"hello"
. In a verbatim string literal, the characters between the delimiters are interpreted verbatim, the only exception being a quote-escape-sequence. In particular, simple escape sequences and hexadecimal and Unicode escape sequences are not processed in verbatim string literals. A verbatim string literal may span multiple lines.
So when you have a chunk of text that looks like this:
PROJCS["OSGB 1936 / British National Grid", |
How would you go about turning this into an escaped string literal (verbatim or regular)?
Being as most programmers are, well, lazy, I didn’t want to do yet another find/replace session. I googled for the first thing that came to mind, “Smart Paste Visual Studio 2008”. I found this great add-in called Smart Paster by Alex Papadimoulis (creator of TheDailyWTF), which adds a highly configurable “Paste As…” context menu:
And now, all I need to do is “Paste As” string, to get this (with a few tweaks):
" PROJCS[\"OSGB 1936 / British National Grid\"," + |
Thanks for the Add-in, Alex!