1. Calculate the length of the string
CopyCode The Code is as follows: var TXT = "Hello world! "
Document. Write (txt. length)
2. indexof () method
How to Use indexof () to locate the first occurrence of a specified character in a string.Copy codeThe Code is as follows: <SCRIPT type = "text/JavaScript">
VaR STR = "Hello world! "// W lower case
Document. Write (Str. indexof ("H") + "<br/>") // 0
Document. Write (Str. indexof ("world") + "<br/>") //-1
Document. Write (Str. indexof ("world") // 6
</SCRIPT>
3. Match () method
Find a specific character in the string, and if it is found, return this character.Copy codeThe Code is as follows: <SCRIPT type = "text/JavaScript">
VaR STR = "Hello world! "
Document. Write (Str. Match ("world") + "<br/>") // world
Document. Write (Str. Match ("world") + "<br/>") // null
Document. Write (Str. Match ("worlld") + "<br/>") // null
Document. Write (Str. Match ("world! ") // World!
</SCRIPT>
4. Replace ()
Replace () is used to replace some characters in a string.Copy codeThe Code is as follows: <SCRIPT type = "text/JavaScript">
VaR STR = "Visit cnblogs.com! "
Document. Write (Str. Replace (/cnblogs.com/, "mamogu.com "))
</SCRIPT>