首页 > 代码库 > guava中String的CharMatcher
guava中String的CharMatcher
1.CharMatcher的field 类型
ANY:匹配任意字符。
NONE:任何字符都不匹配
WHITESPACE:匹配字符里面的空格。
BREAKING_WHITESPACE:匹配字符之间是否被空格隔断。
INVISIBLE:确定字符是否不可见,不可见的字符包括:SPACE_SEPARATOR, LINE_SEPARATOR, PARAGRAPH_SEPARATOR,
CONTROL, FORMAT, SURROGATE, 和PRIVATE_USE
DIGIT: Determines whether a character is a digit according to Unicode. If you only care to match ASCII digits,
you can use inRange(‘0‘, ‘9‘).
JAVA_LETTER:Determines whether a character is a letter according to Java‘s definition. If you only care to
match letters of the Latin alphabet, you can use inRange(‘a‘, ‘z‘).or(inRange(‘A‘, ‘Z‘))。
JAVA_DIGIT:Determines whether a character is a digit according to Java‘s definition. If you only care to match
ASCII digits, you can use inRange(‘0‘, ‘9‘)。
JAVA_LETTER_OR_DIGIT :Determines whether a character is a letter or digit according to Java‘s definition.
JAVA_ISO_CONTROL :Determines whether a character is an ISO control character as specified
by
Character.isISOControl(char)
.JAVA_LOWER_CASE: Determines whether a character is lower case according to Java‘s definition.
JAVA_UPPER_CASE :Determines whether a character is upper case according to Java‘s definition.
ASCII:Determines whether a character is ASCII, meaning that its code point is less than 128.
SINGLE_WIDTH:Determines whether a character is single-width (not double-width). When in doubt,
this matcher errs on the side of returning false (that is, it tends to assume a character is double-width).
2.CharMatcher的经常使用方法与实例
<script src="https://code.csdn.net/snippets/336264.js" type="text/javascript"></script>
运行结果:removeForm:aa
retainForm:aa
replaceFrom_1:afbcd
replaceFrom_2:aThreebcd
trimFrom:cat
trimLeadingFrom:catabb
trimTrailingFrom:abacat
collapseFrom:-ookk-p-
trimAndCollapseFrom:ookk-p
matchesAnyOf:false
or:59F
negate:ddcF
replaceFrom_1:afbcd
replaceFrom_2:aThreebcd
trimFrom:cat
trimLeadingFrom:catabb
trimTrailingFrom:abacat
collapseFrom:-ookk-p-
trimAndCollapseFrom:ookk-p
matchesAnyOf:false
or:59F
negate:ddcF
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。