String object in js

Source: Internet
Author: User
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》

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.