Org. Apache. commons. Lang. stringutils

Source: Internet
Author: User
 

Org. Apache. commons. Lang. stringutils provides many useful string operation methods. By understanding these methods, we can avoid unnecessary repetitive work. The following describes several useful methods:

Check the Null String:

 

StringUtils.isBlank(String str);StringUtils.isNotBlank(String str); 

Abbreviation string:

String test = "this is a test of the abbreviation." system. Out. println (stringutils. abbreviate (test, 10); [console output] This is

Search for nested strings:

String htmlcontent = "<HTML>/N" + "

Verification string:

String test1 = "orange"; string Test2 = "ice9"; string test3 = "ice cream"; string test4 = "820b Judson Avenue"; // judge the letter Boolean t1val = stringutils. isalpha (test1); // returns true // determines if it is a letter or number Boolean t2val = stringutils. isalphanumeric (Test2); // returns true // letter space Boolean t3val = stringutils. isalphaspace (test3); // returns true // alphanumeric Boolean t4val = stringutils. isalphanumericspace (test4); // returns true

Calculate the occurrence frequency of a string:

 File manuscriptFile  =   new  File( " manuscript.txt " );Reader reader  =   new  FileReader( manuscriptFile );StringWriter stringWriter  =   new  StringWriter( ); while ( reader.ready( ) )   { writer.write( reader.read( ) ); }  String manuscript  =  stringWriter.toString( ); //  Convert string to lowercase  manuscript  =  StringUtils.lowerCase(manuscript); //  count the occurrences of "futility"   int  numFutility  =  StringUtils.countMatches( manuscript,  " futility "  );  

Compare different strings:

Int Dist = stringutils. getlevenshteindistance ("Word", "world"); string diff = stringutils. difference ("Word", "world"); int Index = stringutils. indexofdifference ("Word", "world"); system. out. println ("edit distance:" + dist); system. out. println ("difference:" + diff); system. out. println ("Diff index:" + index); [console output] edit distance: 2 difference: lddiff index: 3

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.