Home > Web Front-end > JS Tutorial > JS string interception function example_javascript skills

JS string interception function example_javascript skills

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-05-16 17:06:38
Original
1066 people have browsed it

Use substring() or slice()


Function: split()
Function: Use a specified delimiter to split a string and store it in an array
Example:

Copy the code The code is as follows:

str=”jpg|bmp|gif|ico|png”;
arr=theString.split(”|”) ;
//arr is an array containing the character values ​​"jpg", "bmp", "gif", "ico" and "png"

Function: John()
Function: Combine an array into a string using the delimiter of your choice
Example:
Copy code The code is as follows:

var delimitedString=myArray.join(delimiter);
var myList=new Array("jpg","bmp","gif","ico","png");
var portableList=myList.join(”|”);
//The result is jpg|bmp|gif|ico|png

Function: substring()
Function: character String interception, for example, if you want to get "Minidx" from "MinidxSearchEngine", you need to use substring(0,6)

Function: indexOf()
Function: Return the subscript of the first character matching the substring in the string

Copy codeThe code is as follows:

var myString=”JavaScript”;
var w=myString.indexOf(”v”);w will be 2
var x=myString. indexOf(”S”);x will be 4
var y=myString.indexOf(”Script”);y will also be 4

var z=myString.indexOf(”key”);z will be -1

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
Latest Issues
Where is js written?
From 1970-01-01 08:00:00
0
0
0
js addClass not working
From 1970-01-01 08:00:00
0
0
0
js file code not found
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template