string
type string
Source: compiler/src/builtin_docs/types.hy A UTF-8 text string.
Literals are written in double quotes, with escapes \\, \", \n,
\r, \t, \0, \e, \xHH and \u{HEX}. + and += concatenate two
strings (adding a non-string is a type error). == compares contents,
and <, <=, >, >= order strings by their UTF-8 bytes (string is
Ord, so collections::sort sorts a Vec<string>). s.len() counts
UTF-8 bytes, not characters.
A string is not cast with as: use string::to_bytes for its bytes and
string::format to build strings from other values. A one-byte string
literal coerces to byte where a byte is expected.
Examples#
use tests::assert;
let s = "héllo";
assert!(s.len() == 6);
let greeting = "hi" + ", " + "there";
greeting += "!";
assert!(greeting == "hi, there!");
assert!("apple" < "banana" && "B" < "a");
assert!(show(s) == "héllo");
See also#
Ordcollections::sortVecstring::to_bytesstring::formatbyteint: A 64-bit signed integer, from-9223372036854775808to9223372036854775807.float: A 64-bit IEEE-754 floating-point number.