简体   繁体   English

转换嵌入的unicode字符

[英]converting embedded unicode characters

So I've got some data I'm pulling from an API and when I pull it down into my description string it ends up embedded with &nbsp, &mdash, &#10, and other various unicode characters. 因此,我有一些要从API中提取的数据,当我将其提取到描述字符串中时,它最终会嵌入&nbsp,&mdash,&#10和其他各种unicode字符。 When I push it to my html page it ends up getting displayed on the view. 当我将其推送到html页面时,它最终会显示在视图上。 What can I do to convert this to a readable string? 如何将其转换为可读的字符串?

Is this something I need to parse in my view or in my string on my Controller? 这是我需要在视图中还是在控制器上的字符串中解析的东西?

You may use the HtmlDecode method from System.Web.HttpUtility class 您可以使用System.Web.HttpUtility类中的HtmlDecode方法

    string yourEncodedString = " — 
";
    Console.WriteLine(HttpUtility.HtmlDecode(yourEncodedString));

如果确定字符串是有效的HTML并且信任源,并且可以确定该字符串不会用于XSS攻击 ,则可以在视图中使用@Html.Raw(yourString)将字符串显示为HTML

you can remove those character from the html string using this code 您可以使用以下代码从html string删除这些character

 str = "1 $nbsp;     2     3   4"                                
 var new_str = str_replace(" ", '', $str);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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