String
Functions
Capitalizes each letter in the given string.
String.capitalize("The quick brown fox jumps.") == "The Quick Brown Fox Jumps."
Returns a string representing the character (exactly one UTF-16 code unit) at the specified index. If index is out of range, it returns an empty string.
String.charAt("The quick brown fox jumps over the lazy dog.", 4) == "q"
Returns an integer between 0 and 65535 representing the UTF-16 code unit at the given index.
String.charCodeAt("The quick brown fox jumps over the lazy dog.", 4) == Maybe::Just(113)
Removes all occurrences of the given character from the end of the given string.
String.chopEnd("The quick brown fox jumps.", ".") == "The quick brown fox jumps"
Removes all occurrences of the given character from the start of the given string.
String.chopStart("The quick brown fox jumps.", "T") == "he quick brown fox jumps."
Returns a non-negative integer that is the UTF-16 code point value.
-
If there is no element at pos, returns
Maybe::Nothing
. -
If the element at pos is a UTF-16 high surrogate, returns the code point of the surrogate pair.
-
If the element at pos is a UTF-16 low surrogate, returns only the low surrogate code point.
String.codePointAt("☃★♲", 1) == Maybe::Just(9733)
Joins the given array of strings.
String.concat(["The", "quick", "brown", "fox", "jumps."]) == "Thequickbrownfoxjumps."
Performs a case-sensitive search to determine whether one string may be found within another string, returning true or false as appropriate.
String.contains("The quick brown fox jumps over the lazy dog.", "fox") == true
Drops the number of characters from the end of the string.
String.dropEnd("The quick brown fox jumps.", 1) == "The quick brown fox jumps"
String.dropEnd("The quick brown fox jumps.", 2) == "The quick brown fox jump"
Drops the number of characters from the start of the string.
String.dropStart("The quick brown fox jumps.", 1) == "he quick brown fox jumps."
String.dropStart("The quick brown fox jumps.", 2) == "e quick brown fox jumps."
Determines whether a string ends with the characters of a specified string,
returning true
or false
as appropriate.
String.endsWith("The quick brown fox jumps.", "jumps.") == true
Returns a string created from the specified UTF-16 code unit.
String.fromCharCode(65) == "A"
Returns a string created by using the specified code point.
String.fromCodePoint(9731) == "☃"
Indents the string with the given number of spaces.
String.indent("The quick brown fox jumps.", 2) == " The quick brown fox jumps."
String.indent("The quick brown fox jumps.", 2, "-", false) == "--The quick brown fox jumps."
Returns the index within the calling String object of the first occurrence of
the specified value, returns Maybe::Nothing
if the value is not found.
String.indexOf("The quick brown fox jumps over the lazy dog.", "whale") == Maybe::Nothing
String.indexOf("The quick brown fox jumps over the lazy dog.", "fox") == Maybe::Just(16)
Returns if the given string is an anagram of the other string.
String.isAnagram("The", "quick") == false
String.isAnagram("rail safety", "fairy tales") == true
Returns whether or not the string is blank (only contains whitespace).
String.isBlank("") == true
String.isBlank(" ") == true
String.isBlank("The quick brown fox jumps.") == false
Returns whether or not the string is empty ("").
String.isEmpty("") == true
String.isEmpty(" ") == false
String.isEmpty("The quick brown fox jumps.") == false
Returns whether or not the string is not blank.
String.isNotBlank(" ") == false
String.isNotBlank("The quick brown fox jumps.") == true
Returns whether or not the string is not empty.
String.isNotEmpty(" ") == true
String.isNotEmpty("The quick brown fox jumps.") == true
Joins the given array of string into a single string using the separator.
String.join(["The","quick","brown", "fox", "jumps."], " ") == "The quick brown fox jumps."
Returns the index within the calling String object of the last occurrence of
the specified value, returns Maybe::Nothing
if the value is not found.
String.lastIndexOf("The quick brown fox jumps over the lazy dog.", "whale") == Maybe::Nothing
String.lastIndexOf("The quick brown fox jumps over the lazy dog.", "the") == Maybe::Just(31)
Returns the Unicode Normalization Form of the string.
String.normalize("\u0041\u006d\u0065\u0301\u006c\u0069\u0065") == "\u0041\u006d\u00e9\u006c\u0069\u0065"
Pads the current string with another string (multiple times, if needed) until the resulting string reaches the given length. The padding is applied from the end of the current string.
String.padEnd("5", "0", 2) == "50"
Pads the current string with another string (multiple times, if needed) until the resulting string reaches the given length. The padding is applied from the start of the current string.
String.padStart("5", "0", 2) == "05"
Parameterizes the string:
-
replaces non alphanumeric, dash and underscore characters with dash
-
converts title case to dash case (TitleCase -> title-case)
-
collapses multiple dashes into a single one
-
removes the leading and trailing dash(es)
-
converts to lowercase
String.parameterize("The quick brown fox jumps.") == "the-quick-brown-fox-jumps"
Repeats the given string the given number of times.
String.repeat(3, "The") == "TheTheThe"
Returns a new string with the first matches of a pattern replaced by a replacement.
String.replace("The quick brown fox jumps.", "fox", "bear") ==
"The quick brown bear jumps."
Returns a new string with all matches of a pattern replaced by a replacement.
String.replaceAll("The quick brown fox jumps over the lazy fox.", "fox", "bear") ==
"The quick brown bear jumps over the lazy bear."
Reverses the given string.
String.reverse("The quick brown fox jumps.") == ".spmuj xof nworb kciuq ehT"
Returns number of characters in the given string.
String.size("The quick brown fox jumps.") == 26
Splits the given string using the given separator.
String.split("The quick brown fox jumps.", " ") ==
["The", "quick", "brown", "fox", "jumps."]
Determines whether a string starts with the characters of a specified string,
returning true
or false
as appropriate.
String.startsWith("The quick brown fox jumps.", "The") == true
Returns the given number of characters from the end of the string.
String.takeEnd("The quick brown fox jumps.", 2) == "s."
Returns the given number of characters from the start of the string.
String.takeStart("The quick brown fox jumps.", 2) == "Th"
Convert the given string into an array of strings.
String.toArray("Hello") == ["H", "e", "l", "l", "o"]
Converts the given string to lowercase.
String.toLowerCase("HELLO") == "hello"
Converts the given string to lowercase.
String.toUpperCase("hello") == "HELLO"
Removes whitespace from the beginning and end of the string.
String.trim(" The quick brown fox jumps. ") == "The quick brown fox jumps."
Returns the given string or the given default value if the string is empty.
String.withDefault("", "The quick brown fox jumps.") == "The quick brown fox jumps."
String.withDefault("Hello", "The quick brown fox jumps.") == "Hello"
Wraps the string with the given start and end characters.
String.wrap("The quick brown fox jumps.", "{","}") == "{The quick brown fox jumps.}"