ASP.NET特殊字符问题

编程入门 行业动态 更新时间:2024-10-26 22:16:29
本文介绍了ASP.NET特殊字符问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在ASP.NET中构建了一个自动化的RSS feed,并且出现了很多撇号和连字符:

I'm building an automated RSS feed in ASP.NET and occurrences of apostrophes and hyphens are rendering very strangely:

这里是一个测试渲染为这是一个测试。

"Here's a test" is rendering as "Here’s a test"

我已经设法规避了与英镑符号类似的问题(£ ),如下面的摘录中所示:

I have managed to circumvent a similar problem with the pound sign (£) by escaping the ampersand and building the HTML escape for £ manually as shown in in the extract below:

sArticleSummary = sArticleSummary.Replace("£", "£")

但以下尝试未能解决撇号问题,我们仍然在屏幕上获取 。

But the following attempt is failing to resolve the apostrophe issue, we stil get ’ on the screen.

sArticleSummary = sArticleSummary.Replace("’", "’"")

数据库中的字符串(SQL2005)对于所有意图和目的都显示为纯文本 - 任何人都可以建议为什么似乎是纯文本字符串不断以这种方式出现,如果有人有任何想法如何解决撇号问题,将不胜感激。

The string in the database (SQL2005) for all intents and purposes appears to be plain text - can anyone advise why what seem to be plain text strings keep coming out in this manner, and if anyone has any ideas as to how to resolve the apostrophe issue that'd be appreciated.

感谢你的帮助。

除弗拉基米尔的帮助外,现在看起来问题在于在数据库和它之间的某个地方被加载到字符串var数据从一个撇号转换为 - 有没有人看到过这种情况发生之前或有任何指针?

Further to Vladimir's help, it now looks as though the problem is that somewhere between the database and it being loaded into the string var the data is converting from an apostrophe to ’ - has anyone seen this happen before or have any pointers?

谢谢

Thanks

推荐答案

我猜你的SQL 2005数据库中的列定义为 varchar(N), char(N)或 text 。如果是这样的话on是由于数据库驱动程序使用与数据库中设置的不同代码页设置。

I would guess the the column in your SQL 2005 database is defined as a varchar(N), char(N) or text. If so the conversion is due to the database driver using a different code page setting to that set in the database.

我建议更改此列(任何其他可能包含非标准页面的页面) ASCII数据)至 nvarchar(N), nchar(N)或 nvarchar(max) ,它们可以包含任何Unicode代码点,而不仅仅是代码页定义的代码点。

I would recommend changing this column (any any others that may contain non-ASCII data) to nvarchar(N), nchar(N) or nvarchar(max) respectively, which can then contain any Unicode code point, not just those defined by the code page.

现在我所有的数据库都使用 nvarchar / nchar 来避免这些类型的编码问题。 Unicode字段使用两倍的存储空间,但如果使用此技术,则性能差异很小(SQL引擎在内部使用Unicode)。

All of my databases now use nvarchar/nchar exclusively to avoid these type of encoding issues. The Unicode fields use twice as much storage space but there'll be very little performance difference if you use this technique (the SQL engine uses Unicode internally).

更多推荐

ASP.NET特殊字符问题

本文发布于:2023-11-09 20:15:59,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:特殊字符   ASP   NET

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!