Reputation: 1034
I have a simple question about string. Consider following code:
Dim S1 as String = "abc"
What is the encoding for S1? Is that UTF-8 or depending on user windows local setting?
Upvotes: 7
Views: 9507
Reputation: 172270
It's an implementation detail you should not need to worry about (unless you leave the Basic Multilingual Plane, in which case things get complicated since Char
s represent UTF-16 code units).
When it becomes relevant, i.e., when the string is converted into a byte array, you have to choose the encoding to use:
Dim S1 As String = ...
Dim utf8Bytes = Encoding.UTF8.GetBytes(S1)
Dim utf16Bytes = Encoding.Unicode.GetBytes(S1)
Dim western As New Encoding(1252)
Dim westernBytes = western.GetBytes(S1)
Upvotes: 5