I have the following String
of characters.
string s = "\\u0625\\u0647\\u0644";
When I print the above sequence, I get:
\u0625\u0647\u062
How can I get the real printable Unicode characters instead of this \uxxxx representation?
I have the following String
of characters.
string s = "\\u0625\\u0647\\u0644";
When I print the above sequence, I get:
\u0625\u0647\u062
How can I get the real printable Unicode characters instead of this \uxxxx representation?
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.
Asker posted this as an answer to their question:
I have found the answer:
s = System.Text.RegularExpressions.Regex.Unescape(s);
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 had the following string "\u0001" and I wanted to get the value of it.
I tried a lot but this is what worked for me
int val = Convert.ToInt32(Convert.ToChar("\u0001")); // val = 1;
if you have multiple chars you can use the following technique
var original ="\u0001\u0002";
var s = "";
for (int i = 0; i < original.Length; i++)
{
s += Convert.ToInt32(Convert.ToChar(original[i]));
}
// s will be "12"
I would suggest the use of String.Normalize
. You can find everything here: