ID:139478
 
Code:
client/New(){
var/string="ABC";
world<<"string is [string] and length(string) is [length(string)]";
string+=ascii2text(0);
world<<"string is [string] and length(string) is [length(string)]";
string+=null;
world<<"string is [string] and length(string) is [length(string)]";
}


Problem description:
I'm just trying to throw a null character at the end of a string. The above code will output the following when run:
string is ABC and length(string) is 3
string is ABC and length(string) is 3
string is ABC and length(string) is 3


Is this just not possible in BYOND or am I doing something wrong?
Looks like not. According to the reference:

"In an embedded text expression, null behaves like "". "
In response to tenkuu (#1)
No formatting it that way will not work. Simply put.
For example in C and C++ null character marks end of string. BYOND might do something similar, or just ignore it to prevent bugs.
Since Byond was made with C++, the strings are probably already null terminated. In fact, the extra nulls you are adding might even be getting added too, just growing more 0's on the end.

Either way, a Byond string's length measurement probably ends up as a strlen() if they are using C strings or string::length() if C++ strings. I don't think either takes the null terminator into account for length measurement. So this would be consistent with what you see.
In response to Loduwijk (#4)
Loduwijk wrote:
Either way, a Byond string's length measurement probably ends up as a strlen() if they are using C strings or string::length() if C++ strings. I don't think either takes the null terminator into account for length measurement. So this would be consistent with what you see.

I am pretty sure the null is not being properly added because it would affect the result of the md5 (which reads null bytes). I didn't test in C/C++, but in Python adding a null character does increase the length.
In response to Airjoe (#5)
Here's a secret about strings at least in DMB files: Strings stored in DMB files are not null terminated. A string length is provided to read through the string.

It is very possible as Loduwijk stated that string length is used instead of null. I would like to point out though it does read 0xFF, but you will need a list of macros to use it properly for the next byte after it to properly use them.