JavaScript learning process (1)

Source: Internet
Author: User

Basic Package Type: boolean,number,string.

Here are the main ways to talk about string:

1. Character method

The character methods of String are CharAt () and charCodeAt (), both of which accept only one parameter (based on the 0 positional parameter), charAt () returns the character at that position, and charCodeAt () returns the character encoding;

Example:

var stringvalue = "Hello World";

Alert (Stringvalue.charat (1));// output Letter E

Alert (Stringvalue.charcodeat (1));// Output 101, which is the character encoding of the letter E

2. String manipulation methods

String manipulation methods are concat (), Slice (), substr (), substring (),

Contcat () can return a new string to be stitched together

Example: var stringvalue = "Hello";

Alert (Stringvalue.concat ("World", "!")); / Output Hello world!

Slice (), substr (), substring () can accept two parameters

(1) When 1 parameters are accepted:

Example: var stringvalue = "Hello World";

Alert (Stringvalue.slice (3));// Output lo world

Alert (STRINGVALUE.SUBSTR (3));// Output lo world

Alert (stringvalue.substring (3));// Output lo world

(2) When 2 parameters are accepted

Example: var stringvalue = "Hello World";

Alert (Stringvalue.slice (3,7));// output lo w o position is at 7, so do not return

Alert (STRINGVALUE.SUBSTR (3,7));// output lo worl

Alert (stringvalue.substring (3,7));// output lo w

(3) where the parameter is negative

var stringvalue = "Hello World";

Alert (Stringvalue.slice ( -3));// output rld .... Explanation =-3+11 (string length)

Alert (STRINGVALUE.SUBSTR ( -3));// output Rld

Alert (stringvalue.substring ( -3));//Output Hello world ..... Convert all negative numbers to 0

Alert (Stringvalue.slice (3,-4));// output lo w

Alert (STRINGVALUE.SUBSTR (3,-4));// Output "", the method will be negative first plus string length, minus the second one converted to 0

Alert (stringvalue.substring (3,-4));// output Hel, this method converts all negative numbers to 0

4. Trim () method

Creates a string-by-body that returns characters before and after the deletion of a string, some browsers support Trimleft (), TrimRight ()

Example: var stringvalue = "Hello World";

Alert (Stringvalue.trim ());// Output Hello world

5. String Case Conversion

toLowerCase ()

toUpperCase ()

Tolocallowercase ()//For specific regions

Tolocaluppercase ()//For specific regions

6. String pattern Matching

Match () accepts only one parameter

7. Localcompare () method

JavaScript learning process (1)

Related Article

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.