filename, extension intercept what you have to know.

Source: Internet
Author: User

JS in the use of substr,substring,indexof,lastindexof, etc.

1.substr
SUBSTR (Start,length) is a string that starts at the start position and intercepts length lengths.

var src= "Images/off_1.png";
Alert (SRC.SUBSTR (7,3));

The popup value is: Off

2.substring
SUBSTRING (start,end) represents a string from start to end, including the character of the start position but not the end position.

var src= "Images/off_1.png";
Alert (src.substring (7,10));

The popup value is: Off


3.indexOF
The IndexOf () method returns the position (left-to-right) of the first occurrence of a specified string value in a string. Returns 1 if there is no match, otherwise returns the subscript value of the string where the first occurrence occurs.

var src= "Images/off_1.png";
Alert (Src.indexof (' t '));
Alert (Src.indexof (' I '));
Alert (Src.indexof (' G '));

The popup value is: -1,0,3


4.lastIndexOf
The LastIndexOf () method returns the first character index value of a character or string that appears right-to-left (as opposed to indexof)

var src= "Images/off_1.png";
Alert (Src.lastindexof ('/'));
Alert (Src.lastindexof (' G '));

The popup values are: 6,15

5.filename.size ()-filename.lastindexof ('/')-1

For example, if the path is d:/my documents/tcp/header.h
Filename.lastindexof ('/') returns the number of digits from Start D to the last
Filename.right (8) means a string that starts from the right of the path to the eighth digit.
QString Currentfile=filename.right (Filename.size ()-filename.lastindexof ('/')-1);

The above can be combined with this article http://www.cnblogs.com/zcttxs/archive/2012/05/21/2511947.html see, more clearly.

filename, extension intercept what you have to know.

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.