String
- typeString
The string type
A
Stringliteral is created by putting some text between double quotes.let x = "Hello!";
See the language reference for more information. Roto supports string formatting when a string literal is prefixed with an
f.
- functionappend(self: String, other: String) String
Append a string to another, creating a new string.
"hello".append(" ").append("world") # -> "hello world"
- functionbytes(self: String) StringBytes
Get a view of this string indexed by bytes.
- functionchars(self: String) StringChars
Get a view of this string indexed by chars.
- functioncontains(self: String, needle: String) bool
Check whether a string contains another string.
"haystack".contains("hay") # -> true "haystack".contains("corn") # -> false
- functionends_with(self: String, suffix: String) bool
Check whether a string ends with a given suffix.
"haystack".ends_with("stack") # -> true "haystack".ends_with("black") # -> false
- functionfrom_chars(chars: List[char]) String
Create a new string from a list of characters.
String.from_chars(['h', 'e', 'l', 'l', 'o']) # -> "hello"
- functionlines(self: String) StringLines
Get a view of this string indexed by lines.
- functionrepeat(self: String, n: u32) String
Repeat a string
ntimes and join them."ha".repeat(6) # -> "hahahahahaha"
- functionreplace(self: String, from: String, to: String) String
Replace all occurrences of
fromwithto."In rust we trust".replace("rust", "roto") # -> "In roto we troto"
- functionsplit(self: String, separator: String) List[String]
Split a string by a separator.
"one, two, three".split(", ") # -> ["one", "two", "three"]
- functionstarts_with(self: String, prefix: String) bool
Check whether a string starts with a given prefix.
"haystack".starts_with("hay") # -> true "haystack".starts_with("trees") # -> false