Examples of how JavaScript substring () are used _javascript tips

Source: Internet
Author: User

Definitions and usage
The substring () method extracts characters from a string mediation between two specified subscripts.
Grammar
stringobject.substring (start,stop)

return value
A new string that contains a substring of stringobject whose contents are all characters from the start to the stop-1, whose length is stop minus start.
Description
The substring returned by the substring () method includes the character at the start, but does not include the character at the stop.
If the argument start is equal to the stop, the method returns an empty string (that is, a length of 0). If start is larger than stop, the method swaps the two parameters before extracting the substring.
Tips and Comments
Important: Unlike the slice () and substr () methods, substring () does not accept negative parameters.
Example Explanation
Example 1
In this case, we'll use substring () to extract some characters from the string:

<script type= "Text/javascript" >

var str= "Hello world!"
document.write (Str.substring (3))

</script>

Output: Lo world!

Example 2
In this case, we'll use substring () to extract some characters from the string:

<script type= "Text/javascript" >

var str= "Hello world!"
document.write (str.substring (3,7))

</script>

Output: Lo W

The above is for you to share the use of JavaScript substring (), I hope that you try to do a hands-on, really grasp the use of JavaScript substring ()

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.