quoted string in .Net (@="\u...") convert to unicode

J

Jorgen

I have this situation:
string h = "#u00d8";
h = h.Replace("#","\\"); // => h = @"\u00d8"
WriteLine(h); //=> "\u00d8"

But I wishes to have this situation:
h = "\u00d8";
WriteLine(h); //=> "Ø"

How can I convert a qouted string to a string object so that it can be
parsed by the .Net framework when I call WriteLine (or something
similar).

Conclution: I do not want the Replace() method to add the qouted string
marker (@)!! How can I escape the escape character (@)? :)
 
J

Jon Skeet [C# MVP]

Jorgen said:
I have this situation:
string h = "#u00d8";
h = h.Replace("#","\\"); // => h = @"\u00d8"
WriteLine(h); //=> "\u00d8"

But I wishes to have this situation:
h = "\u00d8";
WriteLine(h); //=> "Ø"

How can I convert a qouted string to a string object so that it can be
parsed by the .Net framework when I call WriteLine (or something
similar).

Conclution: I do not want the Replace() method to add the qouted string
marker (@)!! How can I escape the escape character (@)? :)

Replace isn't adding the @. The debugger is just displaying it.

A "quoted string" *is* a string object. Now, if you want that to be
parsed for things like \uxxxx, I *believe* you'll have to do that
yourself. (I don't know of any classes in the framework which do it for
you.)
 
B

Ben Voigt

c = (Char)UInt16.Parse(g.Value.Substring(2),
NumberStyles.AllowHexSpecifier);



in message
I have this situation:
string h = "#u00d8";
h = h.Replace("#","\\"); // => h = @"\u00d8"
WriteLine(h); //=> "\u00d8"

But I wishes to have this situation:
h = "\u00d8";
WriteLine(h); //=> "Ø"

How can I convert a qouted string to a string object so that it can be
parsed by the .Net framework when I call WriteLine (or something
similar).


Conclution: I do not want the Replace() method to add the qouted string
marker (@)!! How can I escape the escape character (@)? :)
 
C

Chris Dunaway

Jorgen said:
I have this situation:
string h = "#u00d8";
h = h.Replace("#","\\"); // => h = @"\u00d8"
WriteLine(h); //=> "\u00d8"

This won't do what you think it will because the \u (and indeed all
escape sequences) are only interpreted on string literals! If you
replace the value of a string with "\\", you're just going to have a
string with a slash as it's value.

string s = "\u00d8";
WriteLine(s); //Should show the char you want because of the string
litereal

string s = "#u00d8";
s = sReplace("#","\\")
WriteLine(s); //Results in "\u00d8" being written (without the quotes)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top