[OpenSCAD] How to detect chr(0)
paul at brownsbrain.com
Thu Apr 16 23:20:27 EDT 2015
> The chr() function is supposed to return valid unicode characters in utf-8
> encoding, so for example "echo(chr(128512));" is valid and should give the
> smiley character U+1F600.
> Invalid input values will return an empty string, chr(0) is always treated
> as invalid.
> Note: This means that asking for chr(255) will internally result in the
> bytes 0xc3 0xbf and not 0xff. As len() is also utf-8 aware, len(chr(255))
> still returns 1 as it's one character.
Hello and thanks for the input. I'm not sure what you mean by 'internally
result' but here's an example that shows that chr(255) does return a hex
value of 0xFF.
the_text = chr(255);
echo("number of characters = ",len(the_text));
for (ascii_v = [0:255])
if (the_text[i] == chr(ascii_v)) :
if ((ascii_v) == 255):
echo("ASCII value:", ascii_v); // print the ascii
value being checked
ECHO: "number of characters = ", 1
ECHO: "character: ", "y"
ECHO: "ASCII value:", 255
Note that the character that prints like a y with two dots above it has the
hex value of 0xFF, not 0xC3 .0xBF.
View this message in context: http://forum.openscad.org/How-to-detect-chr-0-tp12351p12396.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
More information about the Discuss