string_char_byte
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| string_char_byte [2018/01/24 05:24] – created wolfgangriedmann | string_char_byte [2018/08/20 04:04] (current) – wolfgangriedmann | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== String, Char und Byte ====== | + | ====== String, Char and Byte ====== |
| **In .NET every string is Unicode**. | **In .NET every string is Unicode**. | ||
| Line 10: | Line 10: | ||
| That was possible in VO or other Win32 languages, but it is not more correct in .NET. | 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 '' | In .NET, if reading binary data, you need to use variables defined as '' | ||
| - | + | < | |
| - | < | + | |
| aBitmap := File.ReadAllBytes( " | aBitmap := File.ReadAllBytes( " | ||
| If you are reading text data, you can read it into a string: | If you are reading text data, you can read it into a string: | ||
| - | + | < | |
| - | < | + | |
| cBuffer := File.ReadAllText( " | cBuffer := File.ReadAllText( " | ||
| Line 23: | Line 21: | ||
| Of course, you can convert for and back between strings and character arrays, but you need to specify the '' | Of course, you can convert for and back between strings and character arrays, but you need to specify the '' | ||
| + | To convert byte arrays to string, there are conversion functions. Please look at the Encoding class in the System.Text namespace in the .NET framework documentation. | ||
| + | <code visualfoxpro> | ||
| + | local cString as string | ||
| + | |||
| + | System.Text.Encoding.Unicode.GetString( aBytes )</ | ||
| + | |||
| + | The inverse process is also possible: | ||
| + | <code visualfoxpro> | ||
| + | local cString as string | ||
| + | |||
| + | aBytes := System.Text.Encoding.Unicode: | ||
| + | |||
| + | An array of char values can also be used instead of a string. | ||
| + | |||
| + | To build a string from a char array is very simple, you can use the constructor of the string class: | ||
| + | <code visualfoxpro> | ||
| + | local cString as string | ||
| + | |||
| + | cString := String{ aChars }</ | ||
| + | |||
| + | For the inverse operation (from a string to a char array) you can use a method of the string class: | ||
| + | <code visualfoxpro> | ||
| + | local aChars as char[] | ||
| + | |||
| + | aChars := cString: | ||
| + | If you need to initialize a byte array (as every array), you need to write as follows: | ||
| + | <code visualfoxpro> | ||
| + | aBuffer := Byte[]{ 128 }</ | ||
string_char_byte.1516771457.txt.gz · Last modified: 2018/01/24 05:24 by wolfgangriedmann