Substring substr Slice JS comparison

Source: Internet
Author: User

The stringobject.substring (start,stop) substring () method is used to extract the character of a string intermediary between two specified subscripts.
STRINGOBJECT.SUBSTR (start,length) 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.
Stringobject.slice (start,end) Start subscript of the fragment to extract. End subscript at the end of the fragment to be extracted immediately.

-------------

It is said that SUBSTR is not recommended.

The methods of the String object Slice (), substring (), and substr () (not recommended) can return the specified part of the string.
Slice () is more flexible than substring () because it allows negative numbers to be used as arguments.
Slice () differs from substr () because it specifies a substring with a position of two characters, and substr () specifies a substring with a character position and length.

Also note that String.slice () is similar to Array.slice ().

//////////////////////////
Http://www.w3school.com.cn/jsref/jsref_slice_string.asp
/////////////////////////

Start Required. A nonnegative integer that specifies the position of the first character of the substring to be extracted in the stringobject.
Stop is 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.

Returns a new string value that contains a substring of stringobject whose contents are all characters from start to stop-1, with a length of stop minus start. The substring returned by the substring () method includes the character at start, but does not include the character at the stop.

-----------------
<script type= "Text/javascript" >
var str= "Hello world!" document.write (str.substring (3,7))
</script>

Output: lo w = = = No 7th bit-does not contain stop-the value specified in Firebug or other detection tools

----------------------

Substring substr Slice JS comparison

Related Article

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.