Here I will show you some useful and common string methods. Let’s get right into it.
1. String concat() Method
The concat() method is used to appends two or more strings. The concat() method returns a new string that results from concatenating the original string with the string values that were passed in as parameters.
2. String charAt() method
The charAt() method is used to find out a char value present at the specified index in a string. The index number starts from 0 and goes to n-1, where n is the length of the string.
3. String includes() method
The includes( ) method determines whether a substring is found in a string. if the string found the substring it returns true, if not it returns false.
4. String replace() method
The replace() method searches a string for a specified value, or a regular expression, and returns a new string where the specified values are replaced.
5. String slice() method
The slice() method is used to fetch the part of the string and return the new string. Use the start and end parameters to specify the part of the string you want to fetch. here the first character has the position 0, the second has position 1, and so on.
6. String split() method
The split() method is used to split a string into an array of substrings and return the new array. if in this method empty string (‘’)is used as the separator, the string is split between each character. and The split() method does not change the original string.
7. String trim() method
The trim() method removes whitespace from a string. if any strings have whitespace at start or end then this method removes both whitespaces.
8. String repeat() method
The repeat() method returns a string that has been repeated a desired number of times.
9. String toUpperCase() method
The toUpperCase() method returns the string in the uppercase letter. In other words, it converts all characters of the string into uppercase letters.
10. String toLowerCase() method
The toLowerCase() method returns the string in the lowercase letter. In other words, it converts all characters of the string into lowercase letters.