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 bytes 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, ...)
Strings are comparable, which means that generic operations like < and > work on strings.
annotation |
|
annotation |
|
annotation |
The string for 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.
> 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 |
fun String.append(str :: ReadableString, ...) :: String |
> String.append()
""
> String.append("this")
"this"
> String.append("this", " and ", "that")
"this and that"
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 |
fun String.get(str :: ReadableString, n :: NonnegInt) :: Char |
"aa"
function | ||||
|
> String.substring("hello", 2, 4)
"ll"
> String.substring("hello", 2)
"llo"
function | |||||
| |||||
| |||||
function | |||||
| |||||
| |||||
function | |||||
|
> "hello".utf8_bytes()
#"hello"
function |
fun String.to_int(str :: ReadableString) :: maybe(Int) |
> String.to_int("-42")
-42
> String.to_int("42.0")
#false
> String.to_int("fourty-two")
#false
> "100".to_int()
100
function |
fun String.to_number(str :: ReadableString) :: maybe(Number) |
> 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 |
fun String.upcase(str :: ReadableString) :: String |
|
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.
annotation |
|
annotation |
As always for a veneer, StringCI and ReadableStringCI normally should be used in static mode to help ensure that they have the intended effect.
> "apple" < "BANANA"
#false
#true