码迷,mamicode.com
首页 > 编程语言 > 详细

java判断乱码

时间:2016-09-20 16:42:27      阅读:200      评论:0      收藏:0      [点我收藏+]

标签:

开发需要,判断乱码,baidu了一下,基本都是同一份代码

if (!Character.isLetterOrDigit(c)) {        ->  这个有问题,中文文字被识别成字母及数字

改用:if(!(CharUtils.isAsciiAlpha(c) || CharUtils.isAsciiNumeric(c))){     -> 要apache的lang包

 

Mark一下:

char c=...;

Character.UnicodeBlock ub = Character.UnicodeBlock.of(c);
if (ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS
|| ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A
|| ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_B
|| ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_C
|| ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_D
|| ub == Character.UnicodeBlock.CJK_COMPATIBILITY_FORMS
|| ub == Character.UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS
|| ub == Character.UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS_SUPPLEMENT
|| ub == Character.UnicodeBlock.CJK_SYMBOLS_AND_PUNCTUATION
|| ub == Character.UnicodeBlock.GENERAL_PUNCTUATION
|| ub == Character.UnicodeBlock.HALFWIDTH_AND_FULLWIDTH_FORMS
|| ub == Character.UnicodeBlock.VERTICAL_FORMS

 

常量说明:http://lwjlaser.iteye.com/blog/963211

java判断乱码

标签:

原文地址:http://www.cnblogs.com/abinxm/p/5889065.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!