开发者

String and UTF16

Is the data stored in String object always encoded with UTF16?

I am asking this because my database does stores non English in non Unicode. and I assumed that the data will not b开发者_如何学JAVAe readable because it is read in wrong encoding.

Thanks


Internally .NET strings are in UTF-16, yes... but what's important is how the data is transferred between .NET and your database.

So long as the characters can be represented in Unicode, and the driver performs the appropriate conversion, you should be fine. If you're trying to represent text which can't be represented in Unicode, you may well run into some interesting behaviour.


Yes, .NET strings are always encoded in UTF-16 - with the exception of surrogate pairs that means 2 byte characters.


.NET Strings are ALWAYS Unicode. If your database is unicode you are fine, otherwise you will need to convert the text from whatever format it is in to unicode.


The internal storage of characters (and therefore strings) in .NET is done in UTF-16.

You will need to re-encode the string to the encoding used by your database.

See the Encoding class - this is what you can use to convert a string from one encoding to another.


If you are using ADO.NET with SqlDataCommands (or other types of DataCommands), any required conversion should be handled for you, and you won't need to worry about it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜