@RunWith(JUnit4.class) public class TestStringUtils { private Logger log = LoggerFactory.getLogger(TestStringUtils.class); /*判断空*/ @Test public void testEmpty(){ log.info(StringUtils.isEmpty("aa") + ""); log.info(StringUtils.isEmpty("") + ""); log.info(StringUtils.isEmpty(" ") + ""); log.info(StringUtils.isEmpty("/n") + ""); log.info(StringUtils.isEmpty(null) + ""); } /*判断空白*/ @Test public void testBlank(){ log.info(StringUtils.isBlank("aa") + ""); log.info(StringUtils.isBlank("") + ""); log.info(StringUtils.isBlank(" ") + ""); log.info(StringUtils.isBlank("/r") + ""); log.info(StringUtils.isBlank(null) + ""); } /*去除前导后导空白*/ @Test public void testStrim(){ log.info(StringUtils.trim("aa") ); log.info(StringUtils.trim(" aa ")); log.info(StringUtils.trim(" ") ); log.info(StringUtils.trim("/r weg weg ")); } /*去除前导后导空白,变为null或""返回Null*/ @Test public void testStrimToNull(){ log.info(StringUtils.trimToNull("aa") ); log.info(StringUtils.trimToNull(" aa ")); log.info(StringUtils.trimToNull(" ") ); log.info(StringUtils.trimToNull("/r weg weg ")); } /*去除前导后导空白,变为null或""返回""*/ @Test public void testStrimToEmpty(){ log.info(StringUtils.trimToEmpty("aa") ); log.info(StringUtils.trimToEmpty(" aa ")); log.info(StringUtils.trimToEmpty(" ") ); log.info(StringUtils.trimToEmpty("/b weg weg ")); } /*去除两端空白,不包含制表符*/ @Test public void testStrip(){ log.info(StringUtils.strip("aa") ); log.info(StringUtils.strip(" aa ")); log.info(StringUtils.strip(" ") ); log.info(StringUtils.strip("/b weg weg ")); } /*去除两端空白,不包含制表符, null 或''返回null*/ @Test public void testStripToNull(){ log.info(StringUtils.stripToNull("aa") ); log.info(StringUtils.stripToNull(" aa ")); log.info(StringUtils.stripToNull(" ") ); log.info(StringUtils.stripToNull("/b weg weg ")); } /*去除两端空白,不包含制表符, null 或''返回''*/ @Test public void testStripToEmpty(){ log.info(StringUtils.stripToEmpty("aa") ); log.info(StringUtils.stripToEmpty(" aa ")); log.info(StringUtils.stripToEmpty(" ") ); log.info(StringUtils.stripToEmpty("/b weg weg ")); } /*去除两端在第二个参数中的字符*/ @Test public void testStrip2(){ log.info(StringUtils.strip(" a1a1a ", "a ") ); log.info(StringUtils.strip(" aa ", "a")); log.info(StringUtils.strip(" "," ") ); log.info(StringUtils.strip("/b weg weg ", "/b ")); } /*去除两端在第二个参数中的字符,只去除前导*/ @Test public void testStripStart(){ log.info(StringUtils.stripStart(" a1a1a ", "a ") ); log.info(StringUtils.stripStart(" aa ", "a")); log.info(StringUtils.stripStart(" "," ") ); log.info(StringUtils.stripStart("/b weg weg ", "/b ")); } /*去除两端在第二个参数中的字符,只去除前导*/ @Test public void testStripEnd(){ log.info(StringUtils.stripEnd(" a1a1a ", "a ") ); log.info(StringUtils.stripEnd(" aa ", "a")); log.info(StringUtils.stripEnd(" "," ") ); log.info(StringUtils.stripEnd("/b weg weg ", "/b ")); } /*去除字符串数组中所有字符串前后导*/ @Test public void testStripAll(){ String[] strs = new String[]{"waw ","wweg ", " "}; String[] strings = StringUtils.stripAll(strs); Arrays.stream(strings).forEach(System.out::println); } /*去除字符串数组中所有字符串前后导,有第二个参数的*/ @Test public void testStripAll2(){ String[] strs = new String[]{"waw ","wweg ", " "}; String[] strings = StringUtils.stripAll(strs, "w "); Arrays.stream(strings).forEach(System.out::println); } /*比较相等,大小写敏感*/ @Test public void testEquals(){ System.out.println(StringUtils.equals("aaa","aaa")); System.out.println(StringUtils.equals("aaa","bbb")); System.out.println(StringUtils.equals("aaa","Aaa")); } /*比较相等,大小写不敏感*/ @Test public void testEqualsCase(){ System.out.println(StringUtils.equalsIgnoreCase("aaa","aaa")); System.out.println(StringUtils.equalsIgnoreCase("aaa","bbb")); System.out.println(StringUtils.equalsIgnoreCase("aaa","Aaa")); } /*IndexOf*/ @Test public void testIndexOf(){ System.out.println(StringUtils.indexOf("aaa","a")); } @Test public void testIndexOf2(){ System.out.println(StringUtils.indexOf("aaa","a",1)); } @Test public void testOrdinalIndexOf(){ System.out.println(StringUtils.ordinalIndexOf("aaa","a",2)); } @Test public void testJoin(){ System.out.println(StringUtils.join("a","wg","wg")); } @Test public void testJoin2(){ String[] strs = new String[]{"a","b","c"}; System.out.println(StringUtils.join(strs, ",")); } }
common-langs StringUtils一些用法
最新推荐文章于 2020-07-17 15:25:29 发布