I have the following String
of characters.
string s = \"\\\\u0625\\\\u0647\\\\u0644\";
When I print the above sequence, I get:
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();
I would suggest the use of String.Normalize
. You can find everything here:
http://msdn.microsoft.com/it-it/library/8eaxk1x2.aspx
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.