How to convert latin character to HTML Entity (decimal) in C #?

I want to convert a latin character to html entity code in C #

for example Thrrse Ramdally should convert to

Th & # 8218; r & # 352; se Ramdally

Thanks Vel

+4
source share
1 answer

A possible solution is to encode each character that is outside the ASCII character table (i.e., char> = 128 or character <32):

  String source = @"Thβ€šrΕ se Ramdally";

  String result = String.Concat(source
    .Select(c => (c < 128 && c > 31) 
                    ? c.ToString() 
                    : String.Format("&#{0};", (int) c)));
+3
source

Source: https://habr.com/ru/post/1629547/


All Articles