Home > Web Front-end > JS Tutorial > js substring() string interception function_javascript skills

js substring() string interception function_javascript skills

WBOY
Release: 2016-05-16 17:36:25
Original
1663 people have browsed it


Usage:

Copy code The code is as follows:

str.substring (start, end)
"String Literal".substring(start, end)


where "start" indicates the starting position of the string to be intercepted, and the index starts from 0 Count from the beginning.
"end" indicates the end position of the string to be intercepted, and the index starts from 0.

The substring() function method in JavaScript will return a string containing the substring from start to the end (excluding end).

The substring() function method in JavaScript uses the smaller value of start and end as the starting point of the substring. For example, strvar.substring(0, 3) and strvar.substring(3, 0) will return the same substring. If start or end is NaN or negative, replace it with 0. The length of the substring is equal to the absolute value of the difference between start and end. For example, the length of the substring returned by strvar.substring(0, 3) and strvar.substring(3, 0) is 3.

The following example demonstrates the use of the substring function method in JavaScript:

[Ctrl A select all Note: If you need to introduce external Js, you need to refresh to execute
]
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template