User Tools

Site Tools


string_char_byte

This is an old revision of the document!


String, Char und Byte

In .NET every string is Unicode.

That means that a string of 10 characters has not more 10 bytes like in VO, but normally has 20 (2 byte per character). And the second, not less important issue: when converting between binary data and strings you need to care about charsets.

You cannot more read a binary file from disk or from the network and keep it in a string!

That was possible in VO or other Win32 languages, but it is not more correct in .NET. In .NET, if reading binary data, you need to use variables defined as byte[], that means .NET array of bytes:

local aBitmap as byte[]

aBitmap := File.ReadAllBytes( "c:\data\MyImage.png" )

If you are reading text data, you can read it into a string:

local cBuffer as string

cBuffer := File.ReadAllText( "c:\data\MyText.txt", Encoding.ASCII )

Of course, you can convert for and back between strings and character arrays, but you need to specify the Encoding. In some functions, you can also omit it, but then the .NET framework will use the system defined values, and this can lead to unexpected results.

string_char_byte.1516771457.txt.gz · Last modified: 2018/01/24 05:24 by wolfgangriedmann