Tag: int character expression Regular expression string Run + + div contains
1.split () +a regular expression to intercept. The regex is passed into split (). Returns a string array type. However, interception in this way can have a significant performance loss because the analysis is time-consuming. String Str= "abc,12,3yy98,0"; String[] STRs=str.split (","); for(inti=0,len=strs.length;i<len;i++) {System.out.println (strs[i].tostring ());} Running result: ABC123yy9802. Use the substring () method for string interception. SUBSTRING provides different interception methods through different parameters .2. 1 pass only one parameter for example: String SB= "Bbbdsajjds"; Sb.substring (2); Starts the string from index number 2 and continues to the end of the string. (index value starts from 0);2. 2 Incoming 2 index values string SB= "Bbbdsajjds"; Sb.substring (2, 4), starting from index number 2 to index good 4 end (and does not include index 4 interception, that is, the actual interception of 2 and 3rd characters); The result is as follows: BDSAJJDSBD3The method Stringutils.substringbefore ("Dskeabcee", "E") provided by StringUtils;/Result: dsk/here is the first "E", as the standard. The result of Stringutils.substringbeforelast ("Dskeabcee", "E") is: DSKEABCE here, whichever is the last "E".
Three ways to intercept Java strings