Substring usage in java and javasubstring usage
Substring
1. public String substring (int beginIndex ).
Returns a new string, which is a substring of this string. The substring starts with a character at the specified index until the end of the string.
Parameters:
BeginIndex-the index at the beginning (including ).
Return Value:
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, which is a substring of this string. The substring starts from the specified beginIndex. length: indicates the length of the substring.
Parameters:
BeginIndex-the index at the beginning (including ).
The index at the end of endindex (not included ).
Return Value:
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 return string: "ell"; str. substring () // returns e
Str. substring (1) // return "ello world ";
In addition, this function may have a strange phenomenon when str occurs. substring (5, 0); but the returned result is "hello", str. substring (5, 1) // return to "ello", cut the first digit, and return the remaining.
It can be seen that substring (start, end) can have different instructions, that is, start can be the length to be returned, and end is the number of characters to be removed (starting from the first place ).
In JS, substr (start, length) is easy to use.