JS String intercept function instance

Source: Internet
Author: User
Tags array example function examples join split

This article mainly introduces the JS string intercept function examples, the need for friends can refer to

Use the substring () or slice () function: Split () function: Use a specified delimiter to store a string into an array example: The code is as follows: Str= "Jpg|bmp|gif|ico|png"; Arr=thestring.split ("|"); Arr is an array function that contains the character values "JPG", "BMP", "GIF", "ico" and "PNG": John () function: Combine an array into a string example using the separator you choose: 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 the Jpg|bmp|gif|ico|png function: substring () function: string interception, for example, to get "Minidx" from "minidxsearchengine" to use SUBSTRING (0,6) function: indexOf () function: Returns the subscript code for the first character of the matching substring in the string as follows: Var mystring= "JavaScript"; var w=mystring.indexof ("V"); W'll be 2 var x=mystring.indexof ("S"); x'll be is 4 var y=mystring.indexof ("Script"); Y would al So is 4 var z=mystring.indexof ("key"); Z'll be-1

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.