Try Install Learn Blog API Packages GitHub
Pages
core

Search
Entities

String

Functions

capitalize
(
string
:
String
)
:
String

Capitalizes each letter in the given string.

String.capitalize("The quick brown fox jumps.") == "The Quick Brown Fox Jumps."
charAt
(
string
:
String
index
:
Number
)
:
String

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"
charCodeAt
(
string
:
String
index
:
Number
)
:
Maybe(Number)

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)
chopEnd
(
string
:
String
char
:
String
)
:
String

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"
chopStart
(
string
:
String
char
:
String
)
:
String

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."
codePointAt
(
string
:
String
index
:
Number
)
:
Maybe(Number)

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)

concat
(
array
:
Array(String)
)
:
String

Joins the given array of strings.

String.concat(["The", "quick", "brown", "fox", "jumps."]) == "Thequickbrownfoxjumps."
contains
(
string
:
String
search
:
String
)
:
Bool

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
dropEnd
(
string
:
String
number
:
Number
)
:
String

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"
dropStart
(
string
:
String
number
:
Number
)
:
String

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."
endsWith
(
string
:
String
end
:
String
)
:
Bool

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
fromCharCode
(
charCode
:
Number
)
:
String

Returns a string created from the specified UTF-16 code unit.

String.fromCharCode(65) == "A"
fromCodePoint
(
charCode
:
Number
)
:
String

Returns a string created by using the specified code point.

String.fromCodePoint(9731) == "☃"
indent
(
string
:
String
by
:
Number
character
:
String
includeEmptyLines
:
Bool
)
:
String

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."
indexOf
(
string
:
String
search
:
String
)
:
Maybe(Number)

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)
isAnagram
(
string1
:
String
string2
:
String
)
:
Bool

Returns if the given string is an anagram of the other string.

String.isAnagram("The", "quick") == false
String.isAnagram("rail safety", "fairy tales") == true
isBlank
(
string
:
String
)
:
Bool

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
isEmpty
(
string
:
String
)
:
Bool

Returns whether or not the string is empty ("").

 String.isEmpty("") == true
 String.isEmpty(" ") == false
 String.isEmpty("The quick brown fox jumps.") == false
isNotBlank
(
string
:
String
)
:
Bool

Returns whether or not the string is not blank.

String.isNotBlank("   ") == false
String.isNotBlank("The quick brown fox jumps.") == true
isNotEmpty
(
string
:
String
)
:
Bool

Returns whether or not the string is not empty.

String.isNotEmpty("   ") == true
String.isNotEmpty("The quick brown fox jumps.") == true
join
(
array
:
Array(String)
separator
:
String
)
:
String

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."
lastIndexOf
(
string
:
String
search
:
String
)
:
Maybe(Number)

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)
normalize
(
string
:
String
)
:
String

Returns the Unicode Normalization Form of the string.

String.normalize("\u0041\u006d\u0065\u0301\u006c\u0069\u0065") == "\u0041\u006d\u00e9\u006c\u0069\u0065"
padEnd
(
string
:
String
padString
:
String
targetLength
:
Number
)
:
String

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"
padStart
(
string
:
String
padString
:
String
targetLength
:
Number
)
:
String

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"
parameterize
(
string
:
String
)
:
String

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"

repeat
(
string
:
String
times
:
Number
)
:
String

Repeats the given string the given number of times.

String.repeat(3, "The") == "TheTheThe"
replace
(
string
:
String
pattern
:
String
replacement
:
String
)
:
String

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."
replaceAll
(
string
:
String
pattern
:
String
replacement
:
String
)
:
String

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."
reverse
(
string
:
String
)
:
String

Reverses the given string.

 String.reverse("The quick brown fox jumps.") == ".spmuj xof nworb kciuq ehT"
size
(
string
:
String
)
:
Number

Returns number of characters in the given string.

String.size("The quick brown fox jumps.") == 26
split
(
string
:
String
separator
:
String
)
:
Array(String)

Splits the given string using the given separator.

String.split("The quick brown fox jumps.", " ") ==
  ["The", "quick", "brown", "fox", "jumps."]
startsWith
(
string
:
String
end
:
String
)
:
Bool

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
takeEnd
(
string
:
String
length
:
Number
)
:
String

Returns the given number of characters from the end of the string.

String.takeEnd("The quick brown fox jumps.", 2) == "s."
takeStart
(
string
:
String
length
:
Number
)
:
String

Returns the given number of characters from the start of the string.

String.takeStart("The quick brown fox jumps.", 2) == "Th"
toArray
(
string
:
String
)
:
Array(String)

Convert the given string into an array of strings.

String.toArray("Hello") == ["H", "e", "l", "l", "o"]
toLowerCase
(
string
:
String
)
:
String

Converts the given string to lowercase.

 String.toLowerCase("HELLO") == "hello"
toUpperCase
(
string
:
String
)
:
String

Converts the given string to lowercase.

 String.toUpperCase("hello") == "HELLO"
trim
(
value
:
String
)
:
String

Removes whitespace from the beginning and end of the string.

String.trim("  The quick brown fox jumps.  ") == "The quick brown fox jumps."
withDefault
(
string
:
String
value
:
String
)
:
String

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"
wrap
(
string
:
String
start
:
String
end
:
String
)
:
String

Wraps the string with the given start and end characters.

String.wrap("The quick brown fox jumps.", "{","}") == "{The quick brown fox jumps.}"