What is the default encoding for a string under VB.NET?

I have a simple string question. Consider the following code:

Dim S1 as String = "abc" 

What is the encoding for S1? Is it UTF-8 or depending on the local settings of custom windows?

+6
source share
2 answers

System.String documented for internal use by UTF-16.

+5
source

This is an implementation detail that you don’t need to worry about (unless you leave the Basic Multilingual Plane , in which case it will be difficult, since Char are UTF-16 code units ).

When this becomes relevant, that is, when the string is converted to an array of bytes, you must select 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) 
+4
source

Source: https://habr.com/ru/post/914325/


All Articles