A sequence of Unicode characters (code points).
The following operators are supported for strings:
str[3] // subscript str1 + str2 // concatenation
The number of characters in this string.
size
count
Note: The runtime complexity of this operation is O(n).
O(n)
Facts:
"".length == 0 "abc".length == 3
The index of the last character in this string (same as length - 1).
length - 1
Returns -1 for an empty string.
-1
"".lastIndex == -1 "abc".lastIndex == 2
Tells whether this string is empty.
"".isEmpty !(" ".isEmpty) !("abc".isEmpty)
Tells if all characters in this string have Unicode property "White_Space".
"".isBlank " ".isBlank "\t\n\r".isBlank !("abc".isBlank)
Tells if this string is a valid regular expression according to Regex.
Regex
The MD5 hash of this string's UTF-8 byte sequence as hexadecimal string.
MD5 is cryptographically broken and should not be used for secure applications.
The SHA-1 hash of this string's UTF-8 byte sequence.
SHA-1 is cryptographically broken and should not be used for secure applications.
The SHA-256 cryptographic hash of this string's UTF-8 byte sequence as hexadecimal string.
The first 64 bits of the SHA-256 cryptographic hash of this string's UTF-8 byte sequence.
The Base64 encoding of this string's UTF-8 byte sequence.
The inverse of base64.
base64
"abc".base64.base64Decoded == "abc"
The Unicode characters in this string.
"abc".chars == List("a", "b", "c")
The Unicode code points in this string.
"abc".codePoints == List(0x61, 0x62, 0x63)
Returns the class of this.
this
Returns a string representation of this.
This method is used to convert the values of string interpolation expressions to strings.
Returns this |> transform if this is non-null, and null otherwise.
this |> transform
null
This method is the complement of the ?? operator and the equivalent of an Option type's map and flatMap methods.
??
Option
map
flatMap
Returns the character at index, or null if index is out of range.
index
"abcde".getOrNull(-1) == null "abcde".getOrNull(0) == "a" "abcde".getOrNull(2) == "c" "abcde".getOrNull(4) == "e" "abcde".getOrNull(5) == null
Returns the substring from start until exclusiveEnd.
start
exclusiveEnd
Throws if start is outside range 0..length or exclusiveEnd is outside range start..length.
0
length
"abcde".substring(0, 0) == "" "abcde".substring(0, 1) == "a" "abcde".substring(1, 4) == "bcd" "abcde".substring(4, 5) == "e" "abcde".substring(5, 5) == ""
Returns null if start is outside range 0..length or exclusiveEnd is outside range start..length.
"abcde".substringOrNull(0, 0) == "" "abcde".substringOrNull(0, 1) == "a" "abcde".substringOrNull(1, 4) == "bcd" "abcde".substringOrNull(4, 5) == "e" "abcde".substringOrNull(5, 5) == "" "abcde".substringOrNull(-1, 3) == null "abcde".substringOrNull(0, 6) == null "abcde".substringOrNull(3, 2) == null
Concatenates count copies of this string.
"abc".repeat(0) == "" "abc".repeat(1) == "abc" "abc".repeat(3) == "abcabcabc"
Tells whether this string contains pattern.
pattern
Tells whether this string matches regex in its entirety.
regex
test
Tells whether this string starts with pattern.
Tells whether this string ends with pattern.
Returns the zero-based index of the first occurrence of pattern in this string.
Throws if pattern does not occur in this string.
Returns the zero-based index of the first occurrence of pattern in this string, or null if pattern does not occur in this string.
Returns the zero-based index of the last occurrence of pattern in this string.
Returns the zero-based index of the last occurrence of pattern in this string, or null if pattern does not occur in this string.
Returns the first n characters of this string.
n
limit
Returns this if n is greater than or equal to length.
Returns the longest prefix of this string that satisfies predicate.
predicate
Returns the last n characters of this string.
Returns the longest suffix of this string that satisfies predicate.
Removes the first n characters of this string.
skip
Returns the empty string if n is greater than or equal to length.
Removes the longest prefix of this string that satisfies predicate.
skipWhile
Removes the last n characters of this string.
skipLast
Removes the longest suffix of this string that satisfies predicate.
skipLastWhile
Replaces the first occurrence of pattern in this string with replacement.
replacement
Returns this string unchanged if pattern does not occur in this string.
Replaces the last occurrence of pattern in this string with replacement.
Replaces all occurrences of pattern in this string with replacement.
Replaces the first occurrence of pattern in this string with the return value of mapper.
mapper
Replaces the last occurrence of pattern in this string with the return value of mapper.
Replaces all occurrences of pattern in this string with the return value of mapper.
Replaces the characters between start and exclusiveEnd with replacement.
Inserts replacement at index start if start == exclusiveEnd.
start == exclusiveEnd
Performs a locale-independent character-by-character conversion of this string to uppercase.
Performs a locale-independent character-by-character conversion of this string to lowercase.
Reverses the order of characters in this string.
Removes any leading and trailing characters with Unicode property "White_Space" from this string.
strip
Removes any leading characters with Unicode property "White_Space" from this string.
stripLeft
stripStart
stripLeading
trimLeft
trimLeading
Removes any trailing characters with Unicode property "White_Space" from this string.
stripRight
stripEnd
stripTrailing
trimRight
trimTrailin
Increases the length of this string to width by adding leading chars.
width
char
padLeft
Returns this string unchanged if its length is already equal to or greater than width.
Increases the length of this string to width by adding trailing chars.
padRight
Splits this string around matches of pattern.
Converts the first character of this string to title case.
"pigeon".capitalize() == "Pigeon" "pigeon bird".capitalize() == "Pigeon bird" "".capitalize() == ""
Converts the first character of this string to lower case.
"Pigeon".decapitalize() == "pigeon" "Pigeon Bird".decapitalize() == "pigeon Bird" "".decapitalize() == ""
Parses this string as a signed decimal (base 10) integer.
Throws if this string cannot be parsed as a signed decimal integer, or if the integer is too large to fit into Int.
Int
Returns null if this string cannot be parsed as a signed decimal integer, or if the integer is too large to fit into Int.
Parses this string as a floating point number.
Throws if this string cannot be parsed as a floating point number.
Returns null if this string cannot be parsed as a floating point number.
Parses "true" to true and "false" to false (case-insensitive).
"true"
true
"false"
false
Throws if this string is neither "true" nor "false" (case-insensitive).
Returns null if this string is neither "true" nor "false" (case-insensitive).
A sequence of Unicode characters (code points).