CharMatcher


import com.google.common.base.CharMatcher;


/**
 * @author Andypan
 * @CharMatcherTest.java
 * @{describe}
 * @date 2017年7月26日 上午11:48:52
 */
public class CharMatcherTest
{


public static void testCharMatchers()
{
// removerFrom
String removeFromResult = CharMatcher.isNot('a').removeFrom("abacd");
System.out.println("removeForm:" + removeFromResult);
// retainFrom method
String retainFormResult = CharMatcher.is('a').retainFrom("abacd");
System.out.println("retainForm:" + retainFormResult);
// replaceFrom method
String replaceFormResult1 = CharMatcher.WHITESPACE.replaceFrom("a bcd", 'f');
System.out.println("replaceFrom_1:" + replaceFormResult1);
String replaceFormResult2 = CharMatcher.DIGIT.replaceFrom("a3bcd", "Three");
System.out.println("replaceFrom_2:" + replaceFormResult2);
// trimFrom
String trimFromResult = CharMatcher.anyOf("ab").trimFrom("abacatabb");
System.out.println("trimFrom:" + trimFromResult);
// trimLeadingFrom
String trimLeadingFromResult = CharMatcher.anyOf("ab").trimLeadingFrom("abacatabb");
System.out.println("trimLeadingFrom:" + trimLeadingFromResult);
// trimTrailingFrom
String trimTrailingFromResult = CharMatcher.anyOf("ab").trimTrailingFrom("abacatabb");
System.out.println("trimTrailingFrom:" + trimTrailingFromResult);
// collapseFrom
String collapseFromResult = CharMatcher.anyOf("bre").collapseFrom("bookkeeper", '-');
System.out.println("collapseFrom:" + collapseFromResult);
// trimAndCollapseFrom
String trimAndCollapseFromResult = CharMatcher.anyOf("bre").trimAndCollapseFrom("bookkeeper", '-');
System.out.println("trimAndCollapseFrom:" + trimAndCollapseFromResult);
// matchesAllOf
boolean matchesAllOfResult = CharMatcher.JAVA_UPPER_CASE.matchesAnyOf("hcd");
System.out.println("matchesAnyOf:" + matchesAllOfResult);
// or and negate
String orResult = CharMatcher.JAVA_DIGIT.or(CharMatcher.JAVA_UPPER_CASE).retainFrom("dd59cF");
System.out.println("or:" + orResult);
// negate
String negateResult = CharMatcher.JAVA_DIGIT.negate().retainFrom("dd59cF");
System.out.println("negate:" + negateResult);
}


public static void main(String[] args)
{


testCharMatchers();
}


}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值