JavaScript string Method (Common)

Source: Internet
Author: User

1.toLowerCase (); Converts the letters in a string to uppercase.

For example:

var str = "AbcD";

Str=str.tolowercase ();

The result is: ABCD

2.toUpperCase (); Converts the letters in a string to lowercase.

For example:

var str = "AbcD";

Str=str.touppercase ();

The result is: ABCD

3.substr (); Starts with the specified string, intercepts the specified number of characters, and returns a new string.

For example:

var v = "really rich";

var a = V.substr (UP);

The result is: a very

4.concat (); Inserts the specified string at the beginning of another string, returning a new string.

For example:

var v1 = "large";

var v2 = "Home good";

var v3 = V1.concat (v2);

The result: Hello, everyone.

5.indexof (); Returns the index of the first occurrence of a string, in another string, and returns the index if it does not-1;

For example:

var v = "Profound is the issuance of loans";

var a = V.indexof (of);

The result is: 2

6.lastindexof (); similar to indexof, but returns the last occurrence of the index.

For example:

var v = "Profound is the issuance of loans";

var a = V.lastindexof (of);

The result is: 7

7.replace (); In a string, search for content that matches another string and replace it.

var v = "Hello everyone, my name is XX";

var a = V.replace ("XX", "Zhang San");

The result is: Hello, my name Zhang San.

JavaScript string Method (Common)

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.