Storing special characters in database
Can somebody provide some best practices when storing special characters such as the trademark (tm or r) or copyright (c)? I am storing them in a varchar field with other text in SQL Server, and displaying on an ASP.NET webpage. Right now we are storing t开发者_如何学JAVAhe special character itself and displaying that.
Thanks for any help!
I am storing them in a varchar field ...
There's one problem, at least. For text that could have "special" characters, you need nvarchar
.
Well, with those characters, generally you will render them as
©
So you don't need to do anything special in the DB, but you should be using the "N"-prefixed fields for DB strings, NChar, NVarChar, and so on.
This in an old question but it deserves a new answer: use UTF-8. Browsers, databases and web servers now all support UTF-8 encoding which means that you don't have to encode special characters (except as discussed here, and then, only on the way out).
There are some excellent reasons not to encode data in your database in this answer.
Just use the HTML entities, such as ™
and ©
if you can.
There's no need to switch to nvarchar unless you have an explicit requirement to support Unicode.
精彩评论