JavaScript string extraction function

Source: Internet
Author: User

Web page Special effects string extraction function

Definitions and usage
The substring () method extracts characters from a string mediation between two specified subscripts.

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.

In this case, we will use SUBSTRING () to extract some characters from the string:

    <script language= "J Avascript
    <!--
    var myString = new String ("This is a test");

    var mysubstring = mystring.substring (0,10);
    document.write (' The characters of our we string, ' + myString);
    document.write (', are: ' + mysubstring);
    document.close ();
   
    </script>

In this case, we'll use substring () Extracts some characters from a string:

<title>a simple page</title>
<script Language= "JavaScript"
<!--
Inptxt = "Hello there";
Alert (inptxt.substring (0, 5);
// --
</script>
<body>

</body>

Description
The substring returned by the substring () method includes the character at start, but does not include the character at the end.

If the argument start is equal to end, then the method returns an empty string (that is, the length 0). If start is larger than end, the method swaps the two parameters before extracting the substring.

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.