我该如何转换这个字符串:
This string contains the Unicode character Pi(?)
Run Code Online (Sandbox Code Playgroud)
转换为转义的ASCII字符串:
This string contains the Unicode character Pi(\u03a0)
Run Code Online (Sandbox Code Playgroud)
和反之亦然?
C#中可用的当前编码将π字符转换为"?".我需要保留那个角色.
从 c# 开始,还没有看到重复的。我想做的是:
这个字符串:?ntersport
转换成这个字符串:\u0130ntersport
我找到了一种方法可以转换 unicode 中的所有内容,但不能只转换特殊字符。
在此先感谢您的帮助
编辑:
我试过你的解决方案:
string source = matchedWebIDDest.name;
string parsedNameUnicode = string.Concat(source.Select(c => c < 32 || c > 255 ? "\\u" + ((int)c).ToString("x4") : c.ToString()));
Run Code Online (Sandbox Code Playgroud)
但我得到:“System.Linq.Enumerable+WhereSelectEnumerableIterator`2[Syst??em.Char,System.Strin??g]”