Convert Unicode Escape Sequence to Character


/ Published in: C#
Save to your folder(s)

Convert "\u6211" to "我"


Copy this code and paste it in your HTML
  1. public static string UnicodeToCharacter(string inStr)
  2. {
  3. string result = inStr;
  4. if (Regex.Match(inStr, @".*\\u.*").Success)
  5. {
  6. Regex rx = new Regex(@"\\[uU]([0-9A-F]{4})");
  7. result = rx.Replace(result, delegate(Match match) { return ((char)Int32.Parse(match.Value.Substring(2), NumberStyles.HexNumber)).ToString(); });
  8. }
  9. return result;
  10. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.