Page 1 of 4

chr() and unicode

Posted: Fri Oct 05, 2007 2:39 pm
by pdwyer
How does chr() work with unicode (or doesn't it?)

Syntax

Text$ = Chr(ASCII-Value)
Description

Returns the character associated with the given ASCII value.

Example :
Debug Chr(33) ; Will display "!"
Does the example from the docs become "33,00"? When I use it in the replacestring function in a unicode app is that supported? does it do anything with the zeros?

ASC() seems to work okay but I figure it's easier to ask then write lots of test code to make up for sparse documentation on CHR()

Posted: Fri Oct 05, 2007 2:46 pm
by Kaeru Gaman
works with 16bit args, if Unicode enabled.

give it a try:

Code: Select all

MessageRequester("unitest", "A:"+Chr($fe)+" U:"+Chr($01fe))
if you Debug the two chars, you'll get two times the first one...

Posted: Fri Oct 05, 2007 2:48 pm
by srod
Yep, all is handled okay :

(Compile with the unicode switch)

Code: Select all

a$ = Chr(65)+Chr(66)
Debug PeekW(@a$)
Debug PeekW(@a$+2)

**EDIT : whop, too slow! :)

Posted: Fri Oct 05, 2007 2:50 pm
by Kaeru Gaman
whoo.. this is kind of record to be faster than you, srod...

it was an honor to me.. *bow*

Posted: Fri Oct 05, 2007 2:55 pm
by srod
:lol:

Posted: Fri Oct 05, 2007 3:19 pm
by pdwyer
so "MyString + chr(0)" adds how many zeros?

one wide one I guess

Posted: Fri Oct 05, 2007 5:28 pm
by Trond
pdwyer wrote:so "MyString + chr(0)" adds how many zeros?

one wide one I guess
MyString + Chr(0) returns the original string, because strings are zero terminated.

Posted: Fri Oct 05, 2007 5:43 pm
by Kaeru Gaman
Trond wrote:MyString + Chr(0) returns the original string, because strings are zero terminated.
:lol: that's definitely correct...
but he asked how much it adds, not what much it returns...

Chr(Nr) should add two byte in a Unicode exe.

Posted: Fri Oct 05, 2007 6:17 pm
by Trond
Kaeru Gaman wrote:
Trond wrote:MyString + Chr(0) returns the original string, because strings are zero terminated.
:lol: that's definitely correct...
but he asked how much it adds, not what much it returns...

Chr(Nr) should add two byte in a Unicode exe.
No, it will add 0 bytes.
Let's say Chr(0) returns four bytes: 0, 0, 0, 0. The string concatenation function will treat the first two zeros as the string end. And since there is nothing before the string end nothing will get added.

Posted: Fri Oct 05, 2007 6:29 pm
by Kaeru Gaman
Kaeru Gaman wrote:Chr(Nr) should add two byte in a Unicode exe.
...what exactly is your personal problem with me? :roll:

Posted: Fri Oct 05, 2007 6:42 pm
by Trond
Kaeru Gaman wrote:
Kaeru Gaman wrote:Chr(Nr) should add two byte in a Unicode exe.
...what exactly is your personal problem with me? :roll:
:lol: that's definitely correct...
but he asked how much Chr(0) adds, not how much Chr(Nr) adds.

Posted: Fri Oct 05, 2007 6:46 pm
by Kaeru Gaman
yes, that's right :wink:

I just made a test to be on the sure side... NULLs are not added...
so, the question how much a Zero adds is really nonsense, you got it... :lol:

Posted: Sat Oct 06, 2007 6:03 am
by pdwyer
It's nonesense if it adds a wide zero as that will just terminate the string. the docs are vague though and specifically mention ascii so if it only added one byte (not a word) then the string wouldn't terminate in unicode and the string would be one zero byte longer.

In powerbasic I had to add two myself as it didn't have unicode compile.

Posted: Sat Oct 06, 2007 10:07 am
by Trond
pdwyer wrote:It's nonesense if it adds a wide zero as that will just terminate the string. the docs are vague though and specifically mention ascii so if it only added one byte (not a word) then the string wouldn't terminate in unicode and the string would be one zero byte longer.

In powerbasic I had to add two myself as it didn't have unicode compile.
Let's say Chr() returns just one byte, as you want. It would still have the same effect. Chr(0) would return 0, 0, 0. The string will terminate with the two first null bytes.

Posted: Sat Oct 06, 2007 11:39 am
by pdwyer
Actually I don't want. :)

I just want to know how it works.

I wonder if you can run the PB chm file with a -v? ;)