Var sharp = new String (“sharpleson”);
Here, ‘sharp’ is an object, and ‘sharplesson’ is a string. You can have any name in place of ‘sharp’ and strings in place of ‘sharplesson’.
Note: We have shown you the practical example, instead of showing the copybook syntax. Because, example is better to understand.
- Constructor () – Again, it will return the function which made the object.
- prototype () – If you want to add methods or any properties to the string object, then you can use it.
- length () – It will let you know the number of elements in a string.
- concat () – It means joining, you can use it, if you want to join two strings. It will join it and then return the final result.
- charAt () – You can use it, if you wish to get specific characters from the string. Just mention the index number, and you will get the character that has got the mentioned index.
- charCodeAt() – You can use it to find the Unicode of a character in the mentioned index.
- match () – You can use this method to match string against the regular expression. Once found, it will return it in the array object. In case there is no match, then it will not return anything, It means null.
- replace () – You can use it to replace the string. It will search for the matched string, and it will return the new replaced string.
- search () – It will search for the specific character or string, and returns the index value of that string, or character. Note: if no match found, then it will return -1.
- substr () – You can use this method to get a specific part of the string. You just mention the starting position of the string and closing position as well. Now it will only return the specific characters at the specified position. Note: If you will not mention the closing position, then it will return the entire string after the mentioned starting position.
- toLowerCase () – It will simply convert the string to lower case.
- toUpperCase () – It is opposite to that lowercase, It will convert the string into uppercase.
- toString () – It will return the value of the string object.
- trim () – You can use it to remove the white spaces from both sides of the string.
The output will be:
hello sharplesson readers!
HELLO SHARPLESSON READERS!
We can clearly see that the first line is showing the string in a lower case. The second line shows the specific part that we mentioned, that is from 0 to 3. The last part is showing the string in the Upper case.