简体   繁体   中英

How to convert latin character into HTML Entity (Decimal) in c#?

i want to convert latin character into html entity code in c#

for example Th‚rŠse Ramdally should convert into

Th‚rŠse Ramdally

Thanks vela

Possible solution is to encode every character that's beyond ASCII character table (ie character >= 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)));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM