Joshua Ball
Joshua Ball

Reputation: 23750

Utility to convert an arbitrary string to a .NET string

Is there a utility out there that will convert an arbitrary (or at least from an HTML doc) string into a nicely formatted C# string. The motivation for this is that I am doing a lot of unit tests of HTML docs, and I don't want to load them as files, but rather keep inline strings. I would love to paste some HTML into an editor, and output a reasonably looking C# string. For instance:

Convert this:

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US" xmlns:fb="http://ogp.me/ns/fb#" itemscope itemtype="http://schema.org/">

Into:

@"<html xmlns=""http://www.w3.org/1999/xhtml"" xml:lang=""en-US"" " +
"lang=""en-US"" xmlns:fb=""http://ogp.me/ns/fb#"" itemscope " +
"itemtype=""http://schema.org/"">"

If not, any thoughts on the corner cases for either HTML or .net strings that might be an issue? I am sure it is not as simple as String.Replace("\"", "\"\"") and busting the lines every 80 characters....

Even a plugin for Notepad++ or other editor would work.

Upvotes: 0

Views: 305

Answers (1)

Rasmus Faber
Rasmus Faber

Reputation: 49677

How about Smart Paster?

enter image description here

Visual Studio 2010 version here.

Upvotes: 4

Related Questions