replace MSWord smart quotes in asp.net webform

与世无争的帅哥 提交于 2019-12-02 16:46:44

问题


I am having a problem where users are composing some large chunks of text in MS Word, then pasting that in to the online form. These get entered into the DB as an upside down ?. What are my options to replace these with standard quotes?


回答1:


These smart quotes are a unicode point. All you need is a simple String.Replace to sort them out.

-edit- Something like:

mystring.Replace("\u201C","\"").Replace("\u201D","\"")



回答2:


What are my options to replace these with standard quotes?

The best approach is not to replace them. People want to use “smart quotes”, let them. They're not aberrations that only exist in MS Word, they're perfectly valid Unicode characters, and if your application isn't storing non-ASCII characters right then there's a whole lot more that will go wrong than just smart quotes.

Use UTF-8 encoding for all your web pages and store your content in a Unicode-capable database (eg. if you are using SQL Server, use NVARCHAR) and you'll not only support smart quotes but also accents and other alphabets.




回答3:


You should run the input through the HtmlEncode method, which will convert from “ or ” to “ and ”, allowing you to save those and other higher characters to a format that can be saved without hassle.

Should I also mention Joel's post again?

The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!)



来源:https://stackoverflow.com/questions/1468762/replace-msword-smart-quotes-in-asp-net-webform

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!