JS intercept string substr and substring differences

Source: Internet
Author: User

  1. Defined
    The substr () method extracts a specified number of characters from the start subscript in a string.
    The substring () method is used to extract the character of a string intermediary between two specified subscripts.
  2. syntax
    substr ()          stringobject . substr ( start , length )
    start required. The starting subscript for the substring to extract. Must be numeric. If it is a negative number, the argument declares the position from the end of the string. 1 refers to the last character in the string, and 2 refers to the second-lowest character.
    length optional. The number of characters in the substring. Must be numeric. If this argument is omitted, the string from the beginning of the Stringobject to the end is returned.
    substring ()    stringobject . substring ( Start , stop )
    start required. A nonnegative integer that specifies the position of the first character of the substring to be extracted in the stringobject.
    stop  Optional. A nonnegative integer that is 1 more than the last character of the substring to extract in Stringobject. If this argument is omitted, the returned substring continues until the end of the string.
  3. Contrast
    var a= "abcdefghiklmnopqrstuvwxyz"; var b=a.substr (3,5); var c=a.substring (3,5); The result of the printout is: Defghde Note that the last 5 subscript is not taken to mean that it can only intercept a string of 3, 4 is not intercepted when the subscript is the last [3,5]

JS intercept string substr and substring differences

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.