views:

193

answers:

1
& Eacute ;  \u00C9
& egrave ;  \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.

+3  A: 

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.

Ahmad Mageed
thx! this function could be used to automatize creating a mapping in the opposite direction. :)
Cetin Sert
puhaa ... thx once again for htmlencode and htmldecode *^o^*!!
Cetin Sert
@Cetin no prob! Glad those helped :)
Ahmad Mageed