How can I convert this string:
This string contains the Unicode character Pi(π)
into an escaped A
A small patch to @Adam Sills's answer which solves FormatException
on cases where the input string like "c:\u00ab\otherdirectory\" plus RegexOptions.Compiled
makes the Regex
compilation much faster:
private static Regex DECODING_REGEX = new Regex(@"\\u(?[a-fA-F0-9]{4})", RegexOptions.Compiled);
private const string PLACEHOLDER = @"#!#";
public static string DecodeEncodedNonAsciiCharacters(this string value)
{
return DECODING_REGEX.Replace(
value.Replace(@"\\", PLACEHOLDER),
m => {
return ((char)int.Parse(m.Groups["Value"].Value, NumberStyles.HexNumber)).ToString(); })
.Replace(PLACEHOLDER, @"\\");
}