Page 1 of 1

How come...

Posted: Mon Mar 12, 2012 4:23 pm
by SFSxOI
This was a discussion somewhere else in the forum in the past, in a different aspect, but I can't find it now so i'll re-ask the question in a more direct manner then what i remember that other discussion being:

How come PB string functions like FindString, StringByteLength, etc....exclude the terminating null of a string in their returns?

a string "123456" - Len("123456") = 6 - StringByteLength("123456") = 6 - FindString("123456", Chr(0), 1) = 0 (or FindString("123456", #Null$, 1) = 0)

strings in PB consume memory at "string length + 1" (so I assume strings in PB automatically include a terminating null)

Re: How come...

Posted: Mon Mar 12, 2012 4:46 pm
by luis
Because a PB string it's a particular kind of memory buffer, cannot contain a $00 by definition.
$00 is the termination char. It something beyond the string. It's not part of the string.
It's simply a convention.

Re: How come...

Posted: Mon Mar 12, 2012 4:50 pm
by skywalk
SizeOf(Character) is your friend. :wink:

Re: How come...

Posted: Mon Mar 12, 2012 4:53 pm
by luis
skywalk wrote:SizeOf(Character) is your friend. :wink:
PrintN is nice. The sky is blue.

Re: How come...

Posted: Mon Mar 12, 2012 4:55 pm
by SFSxOI
skywalk wrote:SizeOf(Character) is your friend. :wink:
yeah, I use SizeOf(Character) a lot :)

Re: How come...

Posted: Mon Mar 12, 2012 5:01 pm
by SFSxOI
luis wrote:Because a PB string it's a particular kind of memory buffer, cannot contain a $00 by definition.
$00 is the termination char. It something beyond the string. It's not part of the string.
It's simply a convention.
Yep, thats it, just could not remember. Thanks luis :)