Unicode characters string

后端 未结 3 1663
粉色の甜心
粉色の甜心 2020-12-03 13:34

I have the following String of characters.

string s = \"\\\\u0625\\\\u0647\\\\u0644\";

When I print the above sequence, I get:

相关标签:
3条回答
  • 2020-12-03 14:08

    Try Regex:

    String inputString = "\\u0625\\u0647\\u0644";
    
    var stringBuilder = new StringBuilder();
    foreach (Match match in Regex.Matches(inputString, @"\u([\dA-Fa-f]{4})"))
    {
        stringBuilder.AppendFormat(@"{0}", 
                                   (Char)Convert.ToInt32(match.Groups[1].Value));
    }
    
    var result = stringBuilder.ToString();
    
    0 讨论(0)
  • 2020-12-03 14:23

    I would suggest the use of String.Normalize. You can find everything here:

    http://msdn.microsoft.com/it-it/library/8eaxk1x2.aspx

    0 讨论(0)
  • 2020-12-03 14:32

    If you really don't control the string, then you need to replace those escape sequences with their values:

    Regex.Replace(s, @"\u([0-9A-Fa-f]{4})", m => ((char)Convert.ToInt32(m.Groups[1].Value, 16)).ToString());
    

    and hope that you don't have \\ escapes in there too.

    0 讨论(0)
提交回复
热议问题