英镑符号显示为 £生成 CSV 时
我有一个脚本,它循环遍历网页上的 GridView,并根据值生成 CSV 文件。
报告了一个问题,其中符号显示编码,例如:
Lorem & Ipsum
£100
我使用了 Server.HtmlDecode()
,这已经修复了解码的值,修复了&符号,但是英镑符号是现在显示不同的符号:
Lorem & Ipsum
£100
这是为什么,如何修复此问题以使 Â
字符不出现?
我用来准备 CSV 中使用的初始值的代码是:
Dim Str As String = String.Format("{0}", Server.HtmlDecode(value).Replace(",", "").Replace(Environment.NewLine, " ").Replace(Chr(10), " ").Replace(Chr(13), " "))
这会解码 HTML,替换所有逗号和换行符。
I have a script which loops through a GridView on my web page, and generates a CSV file out of the values.
An issue was reported with this where symbols were being displayed encoded such as:
Lorem & Ipsum
£100
I've used Server.HtmlDecode()
, and this has fixed the decoded the values, fixing the ampersand, however the pound sign is now displaying a different symbol:
Lorem & Ipsum
£100
Why is this, and how can I fix this so that the Â
character doesn't appear?
The code I'm using to prep the initial value for use in CSV is:
Dim Str As String = String.Format("{0}", Server.HtmlDecode(value).Replace(",", "").Replace(Environment.NewLine, " ").Replace(Chr(10), " ").Replace(Chr(13), " "))
This decodes the HTML, replaces any commas and line breaks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的源字符串编码可能与输出编码不匹配。在写出客户端之前设置内容编码,以避免编码发生变化而导致您观察到的结果。
您可以通过设置 Response.ContentEncoding 来做到这一点;例如:
将为您提供 Windows 1252 代码页。您还可以使用 UTF-8 和 ISO 8559-1,或者您想要的任何其他编码。
您还可以使用 globalization 元素在整个应用程序中进行一致的设置你的网络配置。
It's likely that your source string encoding doesn't match the output encoding. Set the content encoding before you write out the client to avoid a change in encoding that produces the results you've observed.
You can do this by setting Response.ContentEncoding; for example:
Will give you the Windows 1252 code page. You can also use UTF-8 and ISO 8559-1, or, indeed any other encoding you want.
You can also set this consistently across your application by using the globalization element in your web.config.