Chr(0,#ENCODING_RAW)

Discuss any general programming issues here
Post Reply
Flinx
Posts: 192
Joined: Sun Feb 14, 2021 9:54 am
Location: Germany

Chr(0,#ENCODING_RAW)

Post by Flinx »

I expected Chr(n,#ENCODING_RAW) and ByteChr(n) to return the same result, but Chr(0,#ENCODING_RAW) returns an empty string. Is that correct?
plouf
Posts: 473
Joined: Sun Feb 04, 2018 11:51 pm
Location: Athens,Greece

Re: Chr(0,#ENCODING_RAW)

Post by plouf »

how do you check it ? look same to me
dont forget strings terminated with a 0 :)

edit
correct myself, Chr is a code point converter , so its 0 which is alreay an empty string (string terminate with 0 so zero is emptty string anyway

bytechr add the value to the string which is a single byte 0 since its an empty string, but because bytechr add the value blind it continue to add zeros
thereofore its a zero to a zero terminated string aka 2 bytes

this example show it

Code: Select all

For i=1 To 10
	strs = strs .. Chr(0,#ENCODING_RAW)
Next	
DebugPrint(StrLen(strs))

For i=1 To 10
	strs2 = strs2 .. ByteChr(0)
Next	
DebugPrint(StrLen(strs2))
Christos
Flinx
Posts: 192
Joined: Sun Feb 14, 2021 9:54 am
Location: Germany

Re: Chr(0,#ENCODING_RAW)

Post by Flinx »

plouf wrote: Sun Mar 17, 2024 8:48 pm dont forget strings terminated with a 0 :)
This is Hollywood, not C :) . In Hollywood strings can contain binary data, this would not be possible with zero terminated strings. From the manual:
"In many programming languages a zero character defines the end of the string. Not so in Hollywood. Hollywood allows you to use as many zero characters as you want in your strings."
User avatar
airsoftsoftwair
Posts: 5446
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: Chr(0,#ENCODING_RAW)

Post by airsoftsoftwair »

Yes, I think the behaviour is wrong. I'll check, thanks for the report!
Post Reply