简体   繁体   English

将字符串转换为普通文本

[英]Convert string to normal text

When I open one file it contains something like this: 当我打开一个文件时,它包含以下内容:

It's that

What is this and how do I convert it to ASCII ? 这是什么,如何将其转换为ASCII?

This is HTML encoding, use WebUtility.HtmlDecode (in System.Net namespace): 这是HTML编码,使用WebUtility.HtmlDecode (在System.Net命名空间中):

string encoded = "It's that";
string decoded = System.Net.WebUtility.HtmlDecode(s);

HttpUtility.HtmlDecode()可以解决问题。

Those are HTML entities. 这些是HTML实体。 They represent ascii characters. 它们代表ASCII字符。 You can decode them using HttpUtility.HTMLDecode(). 您可以使用HttpUtility.HTMLDecode()对其进行解码

If you're just trying to read this one line, you could also rename the file to a .html file and open it in your browser of choice. 如果您只是想阅读这一行,还可以将文件重命名为.html文件,然后在您选择的浏览器中将其打开。 There are even tools that do this online. 甚至还有在线进行此操作的工具

The number between the &# ; &#;之间的数字 is likely an ASCII code. 可能是ASCII码。
Convert the numbers manually or use the HTMLDecode to save yourself some time... 手动转换数字或使用HTMLDecode节省一些时间...

If you're using .Net Framework 4.0 or higher then the System.Net.WebUtility.HtmlDecode(s) will work. 如果您使用的是.Net Framework 4.0或更高版本,则可以使用System.Net.WebUtility.HtmlDecode(s)

I needed this solution for an SSRS report where only 3.5 was supported. 对于仅支持3.5的SSRS报告,我需要此解决方案。 Since the namespace above wasn't available I went the alternate route of 由于上面的命名空间不可用,因此我选择了

System.Web.HttpUtility.HtmlDecode(rawString)

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

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