6.26 Strings
A string is a sequence of Unicode characters. A string works with map-referencing […] to access a character via #%index. A string also works with the ++ operator to append strings, but a +& can be used to append strings with the static guaratee that the result is a string. A string can be used as sequence, in which case it supplies its characters in order.
Although Racket supports mutable strings, the String annotation recognizes only immutable strings, and Rhombus operations generate immutable strings. Some operations allow mutable strings as input, and ReadableString recognizes both mutable and immutable strings.
is
String.append(str, str2, ...)
str.length()
is
String.length(str)
str.get(n)
is
String.get(str, n)
is
String.substring(str, arg, ...)
str.contains(substr)
is
String.contains(str, substr)
is
String.utf8_bytes(str, arg, ...)
is
String.latin1_bytes(str, arg, ...)
is
String.locale_bytes(str, arg, ...)
str.to_int()
is
String.to_int(str)
str.to_number()
is
String.to_number(str)
str.to_string()
is
String.to_string(str)
str.upcase(arg)
is
String.upcase(str, arg)
str.downcase(arg)
is
String.downcase(str, arg)
str.foldcase(arg)
is
String.foldcase(str, arg)
str.titlecase(arg)
is
String.titlecase(str, arg)
str.normalize_nfd()
is
String.normalize_nfd(str)
str.normalize_nfkd()
is
str.normalize_nfc()
is
String.normalize_nfc(str)
str.normalize_nfkc()
is
is
String.grapheme_span(str, arg, ...)
is
String.grapheme_count(str, arg, ...)
str.to_sequence()
is
String.to_sequence(str)
str.copy()
is
String.copy(str)
str.snapshot()
is
String.snapshot(str)
Two strings are equal by is_now as long as they have equal contents, even if one is mutable and the other is immutable.
Strings are comparable, which means that generic operations like < and > work on strings.
annotation | |
| |
annotation | |
| |
annotation | |
Static information associated by String, etc., makes an expression acceptable as a sequence to for in static mode.
function | ||
| ||
function | ||
The string form of a value corresponds to the way that print would print, which means that strings, symbols, identifiers, and keywords convert as their character content in the default #'text mode.
The repr function is a shorthand for to_string with ~mode: #'expr.
For converting a syntax object to a string, see also Syntax.to_source_string.
> to_string(10)
"10"
> to_string('hello')
"hello"
> to_string([1, 2, 3])
"[1, 2, 3]"
"'hello'"
The value is coerced to a string in the same way as by to_string.
> "hello" +& "world"
"helloworld"
> "it goes to " +& 11
"it goes to 11"
"the list [1, 2, 3] has 3 elements"
function | |
|
> String.append()
""
> String.append("this")
"this"
> String.append("this", " and ", "that")
"this and that"
> String.make(5, "x"[0])
"xxxxx"
function | |
> String.length("hello")
5
> "hello".length()
5
function | |||
|
> String.contains("howdy", "how")
#true
> "howdy".contains("how")
#true
> String.contains("howdy", "nope")
#false
> "howdy".contains("nope")
#false
function | |
|
"aa"
function | ||||
|
> String.substring("hello", 2, 4)
"ll"
> String.substring("hello", 2)
"llo"
function | |||||
| |||||
| |||||
function | |||||
| |||||
| |||||
function | |||||
|
> "hello".utf8_bytes()
#"hello"
function | |
|
> String.to_int("-42")
-42
> String.to_int("42.0")
#false
> String.to_int("fourty-two")
#false
> "100".to_int()
100
function | |
|
> String.to_number("-42")
-42
> String.to_number("42.0")
42.0
> String.to_number("fourty-two")
#false
> "3/4".to_number()
3/4
function | ||
| ||
function | ||
function | |
| |
| |
function | |
| |
function | |
| |
function | |
function | |
| |
function | |
| |
function | |
| |
function | |
function | ||||
|
The start and end arguments must be valid indices as for String.substring.
function | ||||
|
The start and end arguments must be valid indices as for String.substring.
function | |
function | |
> "apple".copy()
String.copy("apple")
function | ||
"apple"
annotation | |
| |
annotation | |
As always for a veneer, StringCI and ReadableStringCI work only in static mode (see use_static) to help ensure that they have the intended effect.
> "apple" < "BANANA"
#false
#true