<edit 2016-01-01>Josh wrote:
A other problem you have when changing the file format of your code (File > File format) from plain text to Utf8. Characters like ä, ö, ü will be shown wrong.
Copy your code to clipboard, change your File to UTf8 and paste the code again.
That was a valuable tip, which still works.
However, in PB 5.41 final
the regarding bug in the editor is fixed.
</edit 2016-01-01>Another point to consider results from the fact, that in ASCII mode one character of a string takes 1 byte in memory, while in Unicode mode one character of a string internally takes 2 bytes in memory.
In ASCII mode, it doesn't matter whether we think of the number of characters or the number of bytes. In Unicode mode, it makes a difference:
Code:
s$ = "Hello"
Debug Len(s$) ; -> 5 in both modes
Debug StringByteLength(s$) ; -> 5 in ASCII mode, and 10 in Unicode mode
Code:
foo.s{5} = "12345678"
Debug Len(foo) ; -> 5 in both modes
Debug StringByteLength(foo) ; -> 5 in ASCII mode, and 10 in Unicode mode
AllocateMemory()When we want to
poke a string into memory, then how much memory is to be reserved?
In ASCII mode, we are used to doing this:
Code:
*buffer = AllocateMemory(Len(s$) + 1)
+ 1 is needed for the trailing zero.
In Unicode mode, we can do it like this:
Code:
*buffer = AllocateMemory(2*Len(s$) + 2)
... since the argument of AllocateMemory() is not the number of characters of the string but its number of bytes.
Also note that the trailing zero takes 2 bytes in Unicode mode.
The best bet is to write code that works in ASCII mode
and in Unicode mode:
Code:
*buffer = AllocateMemory(StringByteLength(s$) + SizeOf(Character))