1.2.31 substring Method--Get substring
Book > Java Program Development Reference manual for this article
The substring method implements the interception of a string from the specified index position until the end of the string, and returns a new string.
Syntax 1 public String subString (int beginindex)
Return value: The specified substring.
Parameter: Beginindex is the index at the beginning (including the location).
Example This example uses the substring method to intercept the string strcom, where the index position is truncated from 3 to the end of the string strcom, and the result of the interception is assigned to the string type variable strresult.
String strcom = "I like Java"; Define a string
String strresult = strcom.substring (3);
System.out.println (strresult);
Syntax 2 public String subString (int beginindex, int endIndex)
Return value: The specified substring.
Parameter: Beginindex is the index at the beginning (including the location).
Parameter: Endindex is the end index (excluding the index location).
Example the method implements the beginindex of a string starting at the specified index position until the index position is (ENDINDEX-1) ends and returns a new string of length (Endindex-beginindex).
This example uses the substring method to intercept the string strcom, starting at index position 3 to end at index position 5, and assigning the truncated string to the string type variable strresult.
String strcom = "I like Java"; Define a string
String strresult = strcom.substring (3,5);
System.out.println (strresult);
Split the numbers, hidden a string of strings for a JS reference. Using split splitting to redefine itemcodes numbers
string[] Itemcodes = Hidden.split (",");
Substring,split Method--get substrings, split the numbers