Usage of substring in Java

Source: Internet
Author: User

Tag: Script Dex indicates that the function length is visible string character bis

Substring


1.public String substring (int beginindex).
Returns a new string that is a substring of this string. The substring starts at the specified index and continues to the end of the string.


Parameters:
Beginindex-the index (including) at the beginning.


Return:
The specified substring.


For example:
"Unhappy". SUBSTRING (2) returns "Happy"
"Harbison". SUBSTRING (3) returns "Bison"
"Emptiness". SUBSTRING (9) returns "" (An empty string)

2.public String substring (int beginindex,int length).
Returns a new string that is a substring of this string. The substring starts at the specified beginindex, and length: Indicates the length of the substring.


Parameters:
Beginindex-the index (including) at the beginning.
Endindex at the end of the index (not included).


Return:
The specified substring.


Example:
"Hamburger". Substring (4,8) returns "Urge"
"Smiles". Substring (1,5) returns "Mile"

3.

<script type= "Text/javascript" >

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

</script>

The above returns a string: "ell"; Str.substring (+)//return E

Str.substring (1)//Return to "Ello World";

There is also a strange phenomenon in this function, when str.substring (5,0) occurs; This is what happened, but the return is "Hello", str.substring (5,1)//Return "Ello", cut the first bit, return the rest.

Visible substring (start,end), can have different instructions, that is, start can be the length to return, end is the number of characters to be removed (starting from the first).

In JS, substr (start,length), the use of more convenient.

Usage of substring in Java

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.