package com.likai;
import org.apache.commons.lang3.CharSetUtils;
public class CharSetUtilsDemo {
private static final String s = "Hello word !";
private static final String[] s1 = new String[]{"1","2","a","F","he","ord"};
public static void main(String[] args) {
/*
* 返回符合输入字符范围的字符数.
* <pre>
* CharSetUtils.count(null, *) = 0
* CharSetUtils.count("", *) = 0
* CharSetUtils.count(*, null) = 0
* CharSetUtils.count(*, "") = 0
* CharSetUtils.count("hello", "k-p") = 3
* CharSetUtils.count("hello", "a-e") = 1
* </pre>
*/
System.out.println("count:"+CharSetUtils.count(s, "a-e"));
/*
* 返回符合输入字符数组返回的字符数.
*/
System.out.println("count 数组:"+CharSetUtils.count(s, s1));
/*
* 删除字符串里包含给定字符串里的所有字符.
* <pre>
* CharSetUtils.delete(null, *) = null
* CharSetUtils.delete("", *) = ""
* CharSetUtils.delete(*, null) = *
* CharSetUtils.delete(*, "") = *
* CharSetUtils.delete("hello", "hl") = "eo"
* CharSetUtils.delete("hello", "le") = "ho"
* </pre>
*/
System.out.println("delete :"+CharSetUtils.delete(s, "ewod"));
/*
*
* 删除字符串里包含给定数组的所有字符.
*/
System.out.println("delete2 :"+CharSetUtils.delete(s, s1));
/*
* 返回给定字符串里包含的字符串.
* <pre>
* CharSetUtils.keep(null, *) = null
* CharSetUtils.keep("", *) = ""
* CharSetUtils.keep(*, null) = ""
* CharSetUtils.keep(*, "") = ""
* CharSetUtils.keep("hello", "hl") = "hll"
* CharSetUtils.keep("hello", "le") = "ell"
* </pre>
*/
System.out.println("keep 1:"+CharSetUtils.keep(s, "e"));
/*
* 返回给定字符数组里包含的字符串.
*/
System.out.println("keep 2:"+CharSetUtils.keep(s, s1));
/*
* 排除给定范围内相同的字符并显示字符串.
* * <pre>
* CharSetUtils.squeeze(null, *) = null
* CharSetUtils.squeeze("", *) = ""
* CharSetUtils.squeeze(*, null) = *
* CharSetUtils.squeeze(*, "") = *
* CharSetUtils.squeeze("hello", "k-p") = "helo"
* CharSetUtils.squeeze("hello", "a-e") = "hello"
* </pre>
*/
System.out.println("squeeze:"+CharSetUtils.squeeze(s, "a-z"));
/*
* 排除给定范围内相同的字符并显示字符串.
*/
System.out.println("squeeze2:"+CharSetUtils.squeeze(s, s1));
}
}
commons之CharSetUtils
最新推荐文章于 2023-02-02 10:31:55 发布