Strings
Represents a sequence of unicode characters.
Strings are useful for holding data that can be represented in text form.
Creating Strings
Strings are created using either single or double quotes.
Comparing Strings
Strings can be compared against each other using the ==
operator. This will compare strings in a case-sensitive manner.
Long Strings
Sometimes, your code will include strings which are very long. Rather than having lines that go on endlessly, or wrap at the whim of your editor, you may wish to specifically break the string into multiple lines in the source code without affecting the actual string contents.
You can achieve this using the +
operator to append multiple strings together, like this:
Methods
find()
find()
The find()
method retrieves the result of matching a string against a regular expression.
format()
format()
The format()
method formats according to a format specifier and returns the resulting string.
%s
a string value
endsWith()
endsWith()
The endsWith()
method determines if the given string ends with the given value.
length()
length()
The length()
method returns the length of the given string.
replace()
replace()
The replace()
method replaces a given string within the string.
split()
split()
The split()
method splits a string into a list by the given delimiter.
startsWith()
startsWith()
The startsWith()
method determines if the given string begins wih the given value.
toLowerCase()
toLowerCase()
The toLowerCase()
method converts the given string to lowercase.
toUpperCase()
toUpperCase()
The toUpperCase()
method converts the given string to uppercase.
toString()
toString()
The toString()
method converts the given string to a string. May seem redundant in this instance but this method can be reliably called regardless of the type of value.
toNumber()
toNumber()
The toNumber()
method converts the given string to a number if valid.
trim()
trim()
The trim()
method trims the given string.
trimEnd()
trimEnd()
The trimEnd()
method trims the end of the given string.
trimStart()
trimStart()
The trimStart()
method trims the start of the given string.
Last updated