Three ways to intercept Java strings

Source: Internet
Author: User

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

Related Article

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.