In my c# application i want to convert a string characters to special characters.
My input string is “G\u00f6teborg” and i want the output as Göteborg.
I am using below code,
string name = "G\\u00f6teborg";
StringBuilder sb = new StringBuilder(name);
sb = sb.Replace(@"\\",@"\");
string name1 = System.Web.HttpUtility.HtmlDecode(sb.ToString());
Console.WriteLine(name1);
In the above code the double slash remains the same , it is not replacing to single slash, so after decoding i am getting the output as G\u00f6teborg .
Please help to find a solution for this.
Thanks in advance.
Just remove one of the backslashes:
If you got the input from a user then you need to do more: it’s not enough to replace a backslash because that’s not how the characters are stored internally, the
\uXXXXis an escape sequence representing a Unicode code point.If you want to replace a user input escape sequence by a Unicode code point you need to parse the user input properly. You can use a regular expression for that:
This matches each escape group (
\ufollowed by four hex digits), extracts the hex digits, parses them and translates them to a character.