Introduction to Java substringpublic 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. For example: "Unhappy". SUBSTRING (2) returns "Happy" "Harbison". SUBSTRING (3) returns "Bison" "Emptiness". SUBSTRING (9) returns "" ( An empty string) parameter: Beginindex-index at the beginning (including). Returns: the specified substring. Thrown: indexoutofboundsexception-if beginindex is negative or greater than the length of this String object. --------------------------------------------------------------------------------substringpublic String substring (int beginindex, int endIndex) returns a new string that is a substring of this string. This substring starts at the specified beginindex, EndIndex: ends at the specified endIndex-1. Example: "Hamburger". Substring (3,8) returns "Burge"Smiles". Substring (0,5) returns "Smile"Parameter: Beginindex-the index at the beginning (including). Endindex at the end of the index (not included). Returns: the specified substring. Thrown: indexoutofboundsexception-if beginindex is negative, or length is greater than string length. Example var str= "Hello world!" document.write (str.substring (1,3)); The above returns the string: "El"; str.substring//Return estr.substring (1)//Return to "Ello World"; there will be strange phenomena in this function when str.substring (5,0) appears; This is what happened, but the return is "Hello", str.substring (5,1)//Return "Ello", cut the first bit, return the remaining. Visible substring (start,end), can have different instructions, That is, start can be the length to return, and end is the number of characters to be removed (starting from the first one). In JS, substr (start,length), More convenient to use.-----------------------------------------------------------------------------------------------edit this paragraph in C #variable. Substring (parameter 1, parameter 2);Intercept a part of the string, parameter 1 is the left start number, parameter 2 is to intercept several. such as: string S1 = str. Substring (0,2); There are two overloaded functions in C #, such as code, VS2005 compiled by using system;using system.collections.generic;using system.text;namespace sln_sub{class program{static void Main (string[] args) {string myString = "A quick Fox is jumping over the lazy dog";//substring () in C # there are two heavy Load function//The following example string subString1 = mystring.substring (0);//If the incoming parameter is a long integer, and greater than or equal to 0,//is the beginning of this long integer position,//after interception of all remaining as strings.// If the incoming value is less than the 0,//system throws an argumentOutOfRange exception//indicates that the parameter range is out of bounds string subString2 = mystring.substring (0, 11);//If two long integer parameters are passed in,// The first is the parameter substring at the beginning of the original string//after a parameter is the length of the substring//as the same as the exception Console.WriteLine (SUBSTRING1); Console.WriteLine (SUBSTRING2); Console.ReadLine ();}}} Results of the program output: A quick Fox is jumping over the lazy DogA quick fox In addition, the position of the character A in string A: A.indexof (' A ').edit this paragraph JS usageIn JS, the function declaration: stringobject.substring (Start,stop) Start is the beginning of the original string retrieval, stop is the terminating position of the retrieval, and the returned result does not include the character of Stop.edit this paragraph CB usageUse returns the substring at the specified location within aStringObject. function usage and example strvariable.substring (Start, end)"String Literal".substring (Start, end)Usage Note: Returns a string where start is the beginning of the index,end is the terminating index, and the returned string contains the character starting with index, but does not contain the character of end. This is a method under the String class. Usage examples
| function Substringdemo () {var ss;//declare Variables.var s = "The rain in Spain falls mainly in the plain."; SS = s.substring (n, +); Get Substring.return (ss); Return substring.} |
Intercepting string methods in Java