<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
实验室:
常用方法:
StringUtils.truncate("abcdefg", 7);
StringUtils.wrapIfMissing("ab", 'x');
StringUtils.remove("queued", "ue");
StringUtils.replace("aba", "a", "");
StringUtils.lastIndexOf("sdfafvdsffs", "v");
StringUtils.appendIfMissing("sdsf","dfsf");
StringUtils.substring("abc", 2);
StringUtils.overlay("abcdef", "zzzz", -1, 4);
StringUtils.equals("abc", "ABC");
全量的:
String abl = "1,2,3,4,5,6"; // 11
String abStr = "axcvabnmlKjhduweiu";// 17
String abLagu = "犯我中华者";
String abln = "\n";
// abbreviate = ax...
System.out.println("abbreviate = " + StringUtils.abbreviate(abStr,5));
// abbreviate2 = ...nmlk...
System.out.println("abbreviate2 = " + StringUtils.abbreviate(abStr,5,10));
// abbreviate3 = axcvbnm***
System.out.println("abbreviate3 = " + StringUtils.abbreviate(abStr, "***", 2, 10));
// 中间替换符 abbreviateMiddle = axc***eiu
System.out.println("abbreviateMiddle = " + StringUtils.abbreviateMiddle(abStr, "***", 9));
// 字符串尾部加指定字符 appendIfMissingIgnoreCase() = axcvbnmlkjhduweiuk
System.out.println("appendIfMissingIgnoreCase() = " + StringUtils.appendIfMissingIgnoreCase(abStr,"k"));
// appendIfMissing = 1,2,3,4,5,6,7
System.out.println("appendIfMissing = " + StringUtils.appendIfMissing(abl,",7","5"));
// appendIfMissing = 犯我中华者,虽远必诛
System.out.println("appendIfMissing = " + StringUtils.appendIfMissing(abLagu,",虽远必诛","华"));
// appendIfMissingIgnoreCase = 犯我中华者,虽远必诛
System.out.println("appendIfMissingIgnoreCase = " + StringUtils.appendIfMissingIgnoreCase(abLagu, ",虽远必诛", "华"));
// 首字母达成大写
System.out.println("capitalize = " + StringUtils.capitalize(abStr));
// center = 犯我中华者
System.out.println("center = " + StringUtils.center(abLagu,10));
// center = axcvbnmlkjhduweiu
System.out.println("center = " + StringUtils