android Character.isWhitespace 判断是否是空白char及提供判断空白字符串
2017-10-18 16:21
501 查看
首先看一下这个文档:http://www.yiibai.com/javalang/character_iswhitespace_codepoint.html 这里其实解释的比较详细了。这有个工具类可以判断字符串的:来自Blankj的项目private static boolean isSpace(final String s) {if (s == null) return true;for (int i = 0, len = s.length(); i < len; ++i) {if (!Character.isWhitespace(s.charAt(i))) {return false;}}return true;}然后看一下源码,理解深入一点:/*** Determines if the specified character is white space according to Java.* A character is a Java whitespace character if and only if it satisfies* one of the following criteria:* <ul>* <li> It is a Unicode space character ({@code SPACE_SEPARATOR},* {@code LINE_SEPARATOR}, or {@code PARAGRAPH_SEPARATOR})* but is not also a non-breaking space ({@code '\u005Cu00A0'},* {@code '\u005Cu2007'}, {@code '\u005Cu202F'}).* <li> It is {@code '\u005Ct'}, U+0009 HORIZONTAL TABULATION.* <li> It is {@code '\u005Cn'}, U+000A LINE FEED.* <li> It is {@code '\u005Cu000B'}, U+000B VERTICAL TABULATION.* <li> It is {@code '\u005Cf'}, U+000C FORM FEED.* <li> It is {@code '\u005Cr'}, U+000D CARRIAGE RETURN.* <li> It is {@code '\u005Cu001C'}, U+001C FILE SEPARATOR.* <li> It is {@code '\u005Cu001D'}, U+001D GROUP SEPARATOR.* <li> It is {@code '\u005Cu001E'}, U+001E RECORD SEPARATOR.* <li> It is {@code '\u005Cu001F'}, U+001F UNIT SEPARATOR.* </ul>** <p><b>Note:</b> This method cannot handle <a* href="#supplementary"> supplementary characters</a>. To support* all Unicode characters, including supplementary characters, use* the {@link #isWhitespace(int)} method.** @param ch the character to be tested.* @return {@code true} if the character is a Java whitespace* character; {@code false} otherwise.* @see Character#isSpaceChar(char)* @since 1.1*/public static boolean isWhitespace(char ch) {return isWhitespace((int)ch);}/*** Determines if the specified character (Unicode code point) is* white space according to Java. A character is a Java* whitespace character if and only if it satisfies one of the* following criteria:* <ul>* <li> It is a Unicode space character ({@link #SPACE_SEPARATOR},* {@link #LINE_SEPARATOR}, or {@link #PARAGRAPH_SEPARATOR})* but is not also a non-breaking space ({@code '\u005Cu00A0'},* {@code '\u005Cu2007'}, {@code '\u005Cu202F'}).* <li> It is {@code '\u005Ct'}, U+0009 HORIZONTAL TABULATION.* <li> It is {@code '\u005Cn'}, U+000A LINE FEED.* <li> It is {@code '\u005Cu000B'}, U+000B VERTICAL TABULATION.* <li> It is {@code '\u005Cf'}, U+000C FORM FEED.* <li> It is {@code '\u005Cr'}, U+000D CARRIAGE RETURN.* <li> It is {@code '\u005Cu001C'}, U+001C FILE SEPARATOR.* <li> It is {@code '\u005Cu001D'}, U+001D GROUP SEPARATOR.* <li> It is {@code '\u005Cu001E'}, U+001E RECORD SEPARATOR.* <li> It is {@code '\u005Cu001F'}, U+001F UNIT SEPARATOR.* </ul>* <p>** @param codePoint the character (Unicode code point) to be tested.* @return {@code true} if the character is a Java whitespace* character; {@code false} otherwise.* @see Character#isSpaceChar(int)* @since 1.5*/public static boolean isWhitespace(int codePoint) {// We don't just call into icu4c because of the JNI overhead. Ideally we'd fix that.// Any ASCII whitespace character?if ((codePoint >= 0x1c && codePoint <= 0x20) || (codePoint >= 0x09 && codePoint <= 0x0d)) {return true;}if (codePoint < 0x1000) {return false;}// OGHAM SPACE MARK or MONGOLIAN VOWEL SEPARATOR?if (codePoint == 0x1680 || codePoint == 0x180e) {return true;}if (codePoint < 0x2000) {return false;}// Exclude General Punctuation's non-breaking spaces (which includes FIGURE SPACE).if (codePoint == 0x2007 || codePoint == 0x202f) {return false;}if (codePoint <= 0xffff) {// Other whitespace from General Punctuation...return codePoint <= 0x200a || codePoint == 0x2028 || codePoint == 0x2029 || codePoint == 0x205f ||codePoint == 0x3000; // ...or CJK Symbols and Punctuation?}// Let icu4c worry about non-BMP code points.return isWhitespaceImpl(codePoint);}native static boolean isWhitespaceImpl(int codePoint);这里面已经是判的Unicode了。
相关文章推荐
- Android 判断一个字符串是否含有中文
- android 判断字符串是否为空与比对["=="与equals()的区别]
- Android 判断字符串是否为空
- 分割字符串到数组/替换字符串/返回指定字节长度的字符串/判断是否为浮点数,包括double和float/email判断/是否纯汉字判断/空白判断
- 判断字符串是否是数字标点空白
- 写一函数int fun(char *p)判断一字符串是否为回文,是返回1,不是返回0,出错返回-1
- Android - 使用SharedPreference判断字符串是否修改
- C#判断字符串是否只有数字和字母组成(Regex.IsMatch)
- 关于Android中判断两个字符串是否相等以及是否为空
- Android 判断字符串是否相等
- android判断字符串是否为数字
- Android 判断字符串是否是身份证、邮箱、银行卡、手机号、中文
- 判断空值String.IsNullOrEmpty()和String.IsNullOrWhiteSpace()
- android 应用退到后台,类似最小化moveTaskToBack(),判断是否是task的根isTaskRoot()
- Android判断字符串中是否含字母、中文或数字
- android 字符串工具类 格式化日期字符串 拼接数组 判断字符串是否为空 转换时间显示 转换文件大小 获取中英文字符个数
- android 判断字符串是否为数字或中文或字母 分类: Android JAVA 2015-06-07 21:07 29人阅读 评论(0) 收藏
- Android 获取当前系统时间 时间之间的转换 判断字符串是否日日期类型
- 【Android 开发】使用正则表达式判断输入字符串是否为电话格式
- java.lang.Character.isWhitespace()