Javascript string substring/substr/slice

Source: Internet
Author: User
The two parameters of substring cannot be non-positive integers at the same time: when the two parameters are both positive integers, the return value of the string substring will be a string between the two parameters (including the values at the smaller positions of the two parameters, but it does not include the values of the two parameters at the Greater position, and the return value length is the difference between the two). When a parameter is not a positive integer, that is, 0 or negative, the Return Value of the string substring is the string before the position of the positive integer parameter value. The second parameter of substr must be a positive integer because it represents the number of returned strings. The first parameter can accept positive and negative values: when it is a non-negative integer, the value is calculated based on the parameter values in the forward order of the string. When the value is a negative integer, the value is calculated based on the parameter values in the reverse order of the string. (Note: both adopt positive values.) The two slice parameters are more flexible and can be negative or positive or negative values at the same time. If they are negative, this parameter specifies the position starting from the end of the string. That is to say,-1 refers to the last character of the string,-2 refers to the second to last character, and so on. The comparison method is the same as that of the substring method when the two parameters are both positive integers, regardless of the value they represent the position.

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.