commons之CharSetUtils

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));



}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值