参考commons-lang包中的StringUtils, 可以对我们日常的开发工作有所帮助
空字符串检查
1
|
StringUtils.isBlank(testString)
|
清除空白字符
1 2 3 4 5 6 7 8 9 10
|
String test1 = "t"; String test2 = " A Test "; String test3 = null;
System.out.println( "test1 trimToNull: " + StringUtils.trimToNull( test1 ) );
System.out.println( "test2 trimToNull: " + StringUtils.trimToNull( test2 ) );
System.out.println( "test3 trimToNull: " + StringUtils.trimToNull( test3 ) );
|
取得字符串的缩写
1 2 3 4 5 6 7 8 9
|
String test = "This is a test of the abbreviation."; String test2 = "Test";
System.out.println( StringUtils.abbreviate( test, 15 ) );
System.out.println( StringUtils.abbreviate( test, 5,15 ) );
System.out.println( StringUtils.abbreviate( test2, 10 ) );
|
近期评论