Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert string to unicode representation [duplicate]

Tags:

Possible Duplicate:
Converting Unicode strings to escaped ascii string

How can I convert ä... into something like \u0131... ?

is there any Function for doing this ?

p.s :

beside this way : [ sorry @Kendall Frey :-)]

char a = 'ä';
string escape = "\\u" + ((int)a).ToString("X").PadLeft(4, '0');
like image 495
Royi Namir Avatar asked Nov 08 '12 14:11

Royi Namir


1 Answers

Here's a function to convert a char to an escape sequence:

string GetEscapeSequence(char c)
{
    return "\\u" + ((int)c).ToString("X4");
}

It isn't gonna get much better than a one-liner.

And no, there's no built-in function as far as I know.

like image 193
Kendall Frey Avatar answered Oct 16 '22 14:10

Kendall Frey