Built-in objects in JavaScript -8-string-2

Source: Internet
Author: User
Tags string methods truncated

Learning Goals

1. Mastering the String Object method:

CharAt ()

charCodeAt ()

IndexOf ()

Lastindextof ()

CharAt () and

Grammar:

Stringobjcet.charat (Index)

Function:

returns a string from the index position in the stringobject.

Description

ECMAScript5 can use "square brackets and string indexes" to access specific characters in a string, but IE7 and earlier browsers return undfined.

charCodeAt ()

Grammar:

Stringobject.charcodeat (Index)

Function:

returns The character encoding of the index position character in Stringobject.

Description

ECMAScript5 can use "square brackets and string indexes" to access specific characters in a string, but IE7 and earlier browsers return undfined.

IndexOf ()

Grammar:

Stringoject.indextof ("0")

Function:

Searches a string for the given substring, returning the location of the substring.

return value: Numeric

Description: Returns 1 if the substring is not found .

Learning Goals

1. grasp the method of intercepting the string object:

Slice ()

SUBSTRING ()

SUBSTR ()

Slice ()

Grammar:

Stringvalue.slice (Start,end)

Function:

Truncate substring

Parameter description:

1.start: required to specify the starting position of the substring.

2.end: Optional, indicates where the substring ends, end itself is not within the intercept range, and is truncated to the end of the string when omitted.

3. when the parameter is negative, the passed-in negative value is added to the length of the string.

SUBSTRING ()

Description: The syntax and function are exactly the same as slice () .

The difference is:

1. when the parameter is negative, the parameter is automatically converted to 0.

2.Substring () takes a smaller number as the starting position and a larger number as the end position.

SUBSTR ()

Grammar:

Intercepts a substring.

Parameter description:

1.start: required to specify the starting position of the substring.

2.len: Optional, indicates the total number of characters intercepted, and the end of the string is truncated when omitted.

3. when star is negative, the pass-through is added to the length of the string.

4. when len is negative, an empty string is returned.

Learning Goals

Mastering the comprehensive application of the string method:

Write The JS function, which gets the suffix name of the input parameter, such as input abc.text, returns . Text.

Learning Goals

1. How to Master A String object:

Split()

Replace()

Split ()

Grammar:

Stringobject.split (separator)

Function:

Splits a string into a string array.

return Value: Array

Description

Separator: required, separator.

Replace()

Grammar:

Stringobject.replace (regexp/substr,replacement)

Function:

Substitute some characters in the string for some other characters. or replace a character that matches a regular expression.

return value:string

Parameters:

RegExp: Required, specifies the substring or RegExp object of the pattern to be replaced .

Replacement: required, a string value.

Learning Goals

Other ways to master string methods:

1.toUpperCase ()

2.toLowerCase ()

3. convert string border-left-color to borderleftcolor

toUpperCase () and tolowercase ()

Grammar:

Stringvalue.touppercase ()

Function: Converts a string to uppercase.

Syntax:stringvalue.tolowercase ()

Function: Convert the string to lowercase.

Built-in objects in JavaScript -8-string-2

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.