Unicode literal string

user1373121 picture user1373121 · Jun 24, 2013 · Viewed 34.3k times · Source

I'm sending some JSON in an HTTP POST request. Some of the text within the JSON object is supposed to have superscripts.

If I create my string in C# like this:

string s = "here is my superscript: \u00B9";

... it converts the \u00B9 to the actual superscript 1, which breaks my JSON. I want the \u00B9 to show up exactly as I write it in the the string, not as a superscript.

If I add an escape character, then it shows up like: "here is my superscript: \\u00B9"

I don't want to use an escape character, but I also don't want it to be converted to the actual superscript. Is there a way to have C# not do Unicode conversion and leave it as literally: "\u00B9"?

Answer

NinjaNye picture NinjaNye · Jun 24, 2013

If I understand your question correctly... add the at symbol (@) before the string to avoid the escape sequences being processed

 string s = @"here is my superscript: \u00B9";

http://msdn.microsoft.com/en-us/library/362314fe(v=vs.80).aspx