chr() and unicode

Just starting out? Need help? Post your questions and find answers here.
User avatar
pdwyer
Addict
Addict
Posts: 2813
Joined: Tue May 08, 2007 1:27 pm
Location: Chiba, Japan

chr() and unicode

Post 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()
Paul Dwyer

“In nature, it’s not the strongest nor the most intelligent who survives. It’s the most adaptable to change” - Charles Darwin
“If you can't explain it to a six-year old you really don't understand it yourself.” - Albert Einstein
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post 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...
oh... and have a nice day.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post 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! :)
I may look like a mule, but I'm not a complete ass.
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

whoo.. this is kind of record to be faster than you, srod...

it was an honor to me.. *bow*
oh... and have a nice day.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

:lol:
I may look like a mule, but I'm not a complete ass.
User avatar
pdwyer
Addict
Addict
Posts: 2813
Joined: Tue May 08, 2007 1:27 pm
Location: Chiba, Japan

Post by pdwyer »

so "MyString + chr(0)" adds how many zeros?

one wide one I guess
Paul Dwyer

“In nature, it’s not the strongest nor the most intelligent who survives. It’s the most adaptable to change” - Charles Darwin
“If you can't explain it to a six-year old you really don't understand it yourself.” - Albert Einstein
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post 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.
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post 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.
oh... and have a nice day.
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post 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.
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post 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:
oh... and have a nice day.
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post 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.
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post 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:
oh... and have a nice day.
User avatar
pdwyer
Addict
Addict
Posts: 2813
Joined: Tue May 08, 2007 1:27 pm
Location: Chiba, Japan

Post 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.
Paul Dwyer

“In nature, it’s not the strongest nor the most intelligent who survives. It’s the most adaptable to change” - Charles Darwin
“If you can't explain it to a six-year old you really don't understand it yourself.” - Albert Einstein
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post 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.
User avatar
pdwyer
Addict
Addict
Posts: 2813
Joined: Tue May 08, 2007 1:27 pm
Location: Chiba, Japan

Post 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? ;)
Paul Dwyer

“In nature, it’s not the strongest nor the most intelligent who survives. It’s the most adaptable to change” - Charles Darwin
“If you can't explain it to a six-year old you really don't understand it yourself.” - Albert Einstein
Post Reply