常用函數(shù)如下:
static boolean containsAny(String str, String... set)
接受一個(gè)參數(shù)集語(yǔ)法,看到evaluateSet, 并確定是否有任何的角色出現(xiàn)在指定的字符串中。
static int count(String str, String... set)
接受一個(gè)參數(shù)集語(yǔ)法,看到evaluateSet, 并返回指定數(shù)量的字符出現(xiàn)在字符串。
static String delete(String str, String... set)
接受一個(gè)參數(shù)集語(yǔ)法,看到evaluateSet, 和刪除任何的字符出現(xiàn)在指定的字符串。
static String keep(String str, String... set)
接受一個(gè)參數(shù)集語(yǔ)法,看到evaluateSet, 并保持任何的字符出現(xiàn)在指定的字符串。
static String squeeze(String str, String... set)
根據(jù)參數(shù)二set提供的字母序列,刪除重復(fù)的字符
測(cè)試用例
/**
* 文 件 名: TestCharSetUtils
* 創(chuàng) 建 人: xudaolong
* 創(chuàng)建日期: 16/7/23 14:09
* 郵 箱: xudaolong@vip.qq.com
* 博 客: http://xudaolong.github.io/
* 修改時(shí)間:
* 修改備注:
*/
public class TestCharSetUtils {
public static Logger log = Logger.getLogger(TestCharSetUtils.class);
@Test
public void TestCharSet() {
String memo = "xudaollong";
/**
* 好像都是些過(guò)濾的作用而已
*/
//是否包含指定的字母列
log.info(CharSetUtils.containsAny(memo, "a-v"));
//刪除指定的字母列
log.info(CharSetUtils.delete(memo,"a-c"));
//僅保留指定字母列
log.info(CharSetUtils.keep(memo,"c-z"));
//刪除重復(fù)值
log.info(CharSetUtils.squeeze(memo, "l"));
//計(jì)算指定字母數(shù)
log.info(CharSetUtils.count(memo, "l"));
}
}
結(jié)果
2016-07-23 14:41:34 [INFO] true [main] com.xudalong.CharSetUtils.TestCharSetUtils [com.xudalong.CharSetUtils.TestCharSetUtils.TestCharSet(TestCharSetUtils.java:27)]
2016-07-23 14:41:34 [INFO] xudollong [main] com.xudalong.CharSetUtils.TestCharSetUtils [com.xudalong.CharSetUtils.TestCharSetUtils.TestCharSet(TestCharSetUtils.java:29)]
2016-07-23 14:41:34 [INFO] xudollong [main] com.xudalong.CharSetUtils.TestCharSetUtils [com.xudalong.CharSetUtils.TestCharSetUtils.TestCharSet(TestCharSetUtils.java:31)]
2016-07-23 14:41:34 [INFO] xudaolong [main] com.xudalong.CharSetUtils.TestCharSetUtils [com.xudalong.CharSetUtils.TestCharSetUtils.TestCharSet(TestCharSetUtils.java:33)]
2016-07-23 14:41:34 [INFO] 2 [main] com.xudalong.CharSetUtils.TestCharSetUtils [com.xudalong.CharSetUtils.TestCharSetUtils.TestCharSet(TestCharSetUtils.java:35)]