Javascript String Functions
Contents
- 1 Listing of String functions
- 1.1 .length
- 1.2 charAt(index)
- 1.3 charCodeAt(index)
- 1.4 concat(String1, ..., StringN)
- 1.5 fromCharCode()
- 1.6 indexOf(value)
- 1.7 lastIndexOf(value)
- 1.8 match(regExp)
- 1.9 replace(regExp, value)
- 1.10 search(regExp)
- 1.11 slice(startPos, endPos)
- 1.12 split(token)
- 1.13 substr(startPos, numChars)
- 1.14 subString(startPos, endPos)
- 1.15 toLowerCase()
- 1.16 toUpperCase()
- 1.17 trim()
- 1.18 valueOf()
Listing of String functions
.length
Returns the number of characters in the String.
charAt(index)
Returns the character at the specified index.
charCodeAt(index)
Returns the Unicode of the character at the specified index.
concat(String1, ..., StringN)
Joins Strings and returns a copy of the result.
fromCharCode()
Converts Unicode to characters.
indexOf(value)
Returns the position of the first occurrence of the value in the String. Returns -1 if it does not exist.
lastIndexOf(value)
Returns the position of the last occurrence of the value in the String. Returns -1 if it does not exist.
match(regExp)
Finds a match for the regular expression within the String, returning the matches as an array.
replace(regExp, value)
Finds a match for the regular expression within the String and replaces the resulting subString with a new value.
Replace All
// method 1: literal notation
str.replace(/hello/g, 'hi');
// method 2: RegExp object
str.replace(new RegExp('hello', 'g'), 'hi');
search(regExp)
Finds a match for the regular expression within the String and returns the position of the match.
slice(startPos, endPos)
Extracts the part of the String between the specified start and end positions.
split(token)
Splits the String into an array of subStrings, using the specified token as the delimiter.
substr(startPos, numChars)
Extracts a subString from the String, beginning at the start position through the specified number of characters.
subString(startPos, endPos)
Extracts a subString from the String, between the specified start position and end position.
toLowerCase()
Returns the String in all lowercase characters.
toUpperCase()
Returns the String in all uppercase characters.
trim()
Returns the String without any of the whitespace at either end.
valueOf()
Returns the primitive value of the String.