Home > Web Front-end > JS Tutorial > body text

The functions of substr() and match() in js

一个新手
Release: 2017-09-07 09:56:50
Original
2986 people have browsed it

Study the project code and come across a few String and Array methods that have not been used much recently. Review them:
1. substr()
Usage: used in strings Extract the specified number of characters starting from the start subscript;
Return value: a new string containing length characters starting from the start of string (including start);
Syntax: String.substr(start ,length);
Parameter start: required; the starting index of the string to be extracted. Must be a numeric value. If it is a negative number, then this parameter represents the position starting from the end of the string. For example, -1 refers to the last character in the string, -2 refers to the second to last character in the string, and so on.
Parameter length: optional; the number of characters in the substring to be extracted must be a numerical value. If omitted, the substring starting from the String start position to the end will be returned.
Note: The parameters of substr() specify the starting position and length of the substring, so it can be used instead of substring() and slice().
Important: ECMAscript does not standardize this method and therefore discourages its use.

2. match():
Function: Retrieve a specified value in a string, or find a match for one or more regular expressions; similar to indexOf() and lastIndexOf(), but match( ) returns the specified value, not the position of the string;
Syntax:
match(searchvale);
match(regExp);


The above is the detailed content of The functions of substr() and match() in js. For more information, please follow other related articles on the PHP Chinese website!

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!