.NET是否具有在字符实体及其unicode值之间映射的内置函数?

Cet*_*ert 6 .net c# unicode f# character-entities

& Eacute ;  \u00C9
& egrave ;  \u00E8
& eacute ;  \u00E9
& apos   ;  \u0027
Run Code Online (Sandbox Code Playgroud)

就像是:

f("'") = '\u0027' where f :: string -> char
g('\u0027') = "'" where g :: char -> string
Run Code Online (Sandbox Code Playgroud)

或者是否有第三方库具有BSD或MIT风格的许可免费许可证?否则我将不得不创建自己的映射,但它非常紧急,我不想错过可用的功能.

Ahm*_*eed 3

您可以使用SecurityElement.Escape 方法从 unicode 转换为字符实体:

char c = '\u0027';
string entity = System.Security.SecurityElement.Escape(c.ToString());
Console.WriteLine(entity);
Run Code Online (Sandbox Code Playgroud)

至于反向操作,我认为你运气不好,需要编写自己的方法。

编辑:您可能还会发现HttpUtility.HtmlEncodeHttpUtility.HtmlDecode方法很有用。要使用它们,您需要添加对 System.Web 的引用。