String types in CM are for the most part analogous to their representation in C/C++: null-terminated character arrays.
String literals are formed by enclosing sequences of character literals in pairs of quotation marks. Special characters may need to be escaped with backslashes.
The corresponding type of the characters that comprise a string and the size of each character is defined by the string type.
str
Comprised of char
s, which are UTF16-encoded 2-byte characters. This corresponds to wchars ("wide characters") in some C implementations.
cstr
Comprised of cchar
s, which are 1-byte characters analogous to char in ANSI C and require a codepage to interpret if outside the standard lower set of ASCII.
str8
The str8 type defines null-terminated character sequences encoded with the UTF-8 character encoding. UTF-8 is a variable-length format. Each character is 1-4 cchar
s.
in Operator For Strings
The in operator can be used for testing if a character is contained in a string.
{ str stringEx = "Foobar"; pln(#"Foo" in stringEx); pln(#"foo" in stringEx); pln(#"bear" in stringEx); pln(#'o' in stringEx); }
Output:
"Foo" in stringEx=true "foo" in stringEx=false "bear" in stringEx=false 'o' in stringEx=true
Comments
0 comments
Please sign in to leave a comment.