开发者

Does .NET have built-in functions mapping between character entities and their unicode values?

开发者 https://www.devze.com 2022-12-21 21:46 出处:网络
& Eacute ;\\u00C9 & eg开发者_StackOverflow社区rave ;\\u00E8 & eacute ;\\u00E9 & apos;\\u0027
& Eacute ;  \u00C9
& eg开发者_StackOverflow社区rave ;  \u00E8
& eacute ;  \u00E9
& apos   ;  \u0027

something like:

f("'") = '\u0027' where f :: string -> char
g('\u0027') = "'" where g :: char -> string

Or is there a third-party library with a BSD or MIT style permissive free license with something of this sort? Otherwise I'll have to create my own mapping but it's quite urgent and I don't want to miss out on available functionality.


You can use the SecurityElement.Escape method to go from unicode to character entity:

char c = '\u0027';
string entity = System.Security.SecurityElement.Escape(c.ToString());
Console.WriteLine(entity);

As for going in reverse, I think you're out of luck and will need to write your own approach.

EDIT: you might also find the HttpUtility.HtmlEncode and HttpUtility.HtmlDecode methods useful. To use them you'll need to add a reference to System.Web.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号