The String object can be used to process or format text strings and determine and locate substrings in strings. & Amp; nbsp; String object common methods are summarized as follows: & quot; helloWorld & quot;. toUpperCase () return Conversion
The String object can be used to process or format text strings and determine and locate substrings in strings.
Common Methods for String objects are summarized as follows:
"HelloWorld". toUpperCase () returns a string converted to uppercase letters
"HelloWorld". toLowerCase () returns a string converted to lowercase letters
"HelloWorld". substr (1, 5) returns a substring of the specified length starting from the specified position
"HelloWorld". split ("o") splits the string into substrings and returns the result (array) as a string array.
"HelloWorld". slice () returns the string segment after string Truncation
"HelloWorld". replace ("o", "O") returns the content of the string after text replacement (only replace the first matching result)
"HelloWorld". lastIndexOf ("o") returns the last occurrence of the substring in the string.
"HelloWorld". indexOf ("World") returns the character position of the substring that appears for the first time in the string.
《script》 var str = "www.phpddt.COM"; document.write(str.indexOf("php")+"
");//4 document.write(str.lastIndexOf("php")+"
"); //4 document.write(str.replace("php","PHP")+"
");//www.PHPddt.COM document.write(str.slice(1,5)+"
");//ww.p document.write(str.substr(1,5)+"
");//ww.ph document.write(str.toLowerCase(str)+"
");//www.phpddt.com document.write(str.toUpperCase(str)+"
");//WWW.PHPDDT.COM 《script》