本文介绍了java判断中英文符号、标点的实现,分享给大家,具体如下:

方法一、用unicodeblock和unicodescript判断

在java中,主要使用 character类处理字符有关功能,而jdk 1.7中character是按照unicode 6.0版本实现的,所以这个要先学习下常用的 unicode编码。

其中的unicodeblock 和 unicodescript类可以帮助我们判断字符类型,unicodeblock是unicode标准协会组织unicode码的一个基本单位,实际上一个 unicodeblock代表一片连续的unicode号码段,unicodeblock之间不重叠。例如,通常我们利用unicode编码是否在 0x4e00–0x9fcc 来判断某字符是否为汉字,就是因为,有个unicodeblock 专门划分为存储汉字 (准确的说是 cjk统一汉字),这个unicodeblock叫做 cjk unified ideographs,总共定义了 74,617 个汉字。

unicodeblock 与 unicodescript 关系:

所以unicodescript 是从语言书写规则层次对unicode字符的分类,这是用使用角度划分,而unicodeblock是从硬的编码角度划分。

1. unicodeblock是简单的数值范围 (其中可能有些block中会有一些尚未分配字符的“空号”)。

2. 在一个unicodescript中的字符可能分散在多个unicodeblock中;

3. 一个unicodeblock中的字符可能会被划进多个unicodescript中。

判别中文标点符号。

因为中文的标点符号主要存在于以下5个unicodeblock中,

u2000-general punctuation (百分号,千分号,单引号,双引号等)

u3000-cjk symbols and punctuation ( 顿号,句号,书名号,〸,〹,〺 等;ps: 后面三个字符你知道什么意思吗? : )    )

uff00-halfwidth and fullwidth forms ( 大于,小于,等于,括号,感叹号,加,减,冒号,分号等等)

ufe30-cjk compatibility forms  (主要是给竖写方式使用的括号,以及间断线﹉,波浪线﹌等)

ufe10-vertical forms (主要是一些竖着写的标点符号,    等等)

// 根据unicodeblock方法判断中文标点符号

public boolean ischinesepunctuation(char c) {

character.unicodeblock ub = character.unicodeblock.of(c);

if (ub == character.unicodeblock.general_punctuation

|| ub == character.unicodeblock.cjk_symbols_and_punctuation

|| ub == character.unicodeblock.halfwidth_and_fullwidth_forms

|| ub == character.unicodeblock.cjk_compatibility_forms

|| ub == character.unicodeblock.vertical_forms) {

return true;

} else {

return false;

}

}

方法二、用字符范围判断

static boolean issymbol(char ch)

{

if(iscnsymbol(ch)) return true;

if(isensymbol(ch))return true;

if(0x2010 <= ch && ch <= 0x2017) return true;

if(0x2020 <= ch && ch <= 0x2027) return true;

if(0x2b00 <= ch && ch <= 0x2bff) return true;

if(0xff03 <= ch && ch <= 0xff06) return true;

if(0xff08 <= ch && ch <= 0xff0b) return true;

if(ch == 0xff0d || ch == 0xff0f) return true;

if(0xff1c <= ch && ch <= 0xff1e) return true;

if(ch == 0xff20 || ch == 0xff65) return true;

if(0xff3b <= ch && ch <= 0xff40) return true;

if(0xff5b <= ch && ch <= 0xff60) return true;

if(ch == 0xff62 || ch == 0xff63) return true;

if(ch == 0x0020 || ch == 0x3000) return true;

return false;

}

static boolean iscnsymbol(char ch) {

if (0x3004 <= ch && ch <= 0x301c) return true;

if (0x3020 <= ch && ch <= 0x303f) return true;

return false;

}

static boolean isensymbol(char ch){

if (ch == 0x40) return true;

if (ch == 0x2d || ch == 0x2f) return true;

if (0x23 <= ch && ch <= 0x26) return true;

if (0x28 <= ch && ch <= 0x2b) return true;

if (0x3c <= ch && ch <= 0x3e) return true;

if (0x5b <= ch && ch <= 0x60) return true;

if (0x7b <= ch && ch <= 0x7e) return true;

return false;

}

static boolean ispunctuation(char ch){

if(iscjkpunc(ch)) return true;

if(isenpunc(ch)) return true;

if(0x2018 <= ch && ch <= 0x201f) return true;

if(ch == 0xff01 || ch == 0xff02) return true;

if(ch == 0xff07 || ch == 0xff0c) return true;

if(ch == 0xff1a || ch == 0xff1b) return true;

if(ch == 0xff1f || ch == 0xff61) return true;

if(ch == 0xff0e) return true;

if(ch == 0xff65) return true;

return false;

}

static boolean isenpunc(char ch){

if (0x21 <= ch && ch <= 0x22) return true;

if (ch == 0x27 || ch == 0x2c) return true;

if (ch == 0x2e || ch == 0x3a) return true;

if (ch == 0x3b || ch == 0x3f) return true;

return false;

}

static boolean iscjkpunc(char ch){

if (0x3001 <= ch && ch <= 0x3003) return true;

if (0x301d <= ch && ch <= 0x301f) return true;

return false;

}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持萬仟网。

希望与广大网友互动??

点此进行留言吧!

java 判断英文标点_Java判断中英文符号、标点的实现相关推荐

  1. java 1 2 等于_java 判断语句中一个等于号和两个等于号的区别是什么?

    展开全部 一个等于号 是赋值操作的意e5a48de588b63231313335323631343130323136353331333365633864思 比如 int i = 5 就是把i的值赋为5 ...

  2. java 判断图片格式_Java判断上传图片格式的实例代码

    先给大家介绍下java判断上传图片格式. 由于客户上传图片将png的图片的后缀名改为jpg,所以通过后缀名判断不行,用下面这个方法可以 //判断是否是JPG格式 log.info("-1-- ...

  3. java 字符是否存在_java判断字符是否存在的方法

    java判断字符是否存在的方法 发布时间:2020-06-10 09:41:51 来源:亿速云 阅读:165 作者:Leah 这篇文章给大家分享的是java判断字符是否存在的方法.小编觉得挺实用的,因 ...

  4. java 判断是不是图片_java判断是否是图片

    java判断是否是图片的方法: 1.通过判断文件后缀名判断是否是图片String extension = ""; int i = fileName.lastIndexOf('.') ...

  5. if js 判断成绩等级_Java判断语句的语法和使用

    文章导读 [在生活中,常常会遇到许多需要判断的情况,在这种情况下,需要根据一些条件作出决定和选择.例如,在我们打算出门时,需要判断天气怎么样,如果下雨了,就要带上雨伞:外出旅行时,需要根据不同情况,选 ...

  6. java字符串校验,过滤筛选中英文符号

    需求说明:空格.符号.全数字 ,符号中英文符号的文本,要拦截,不让通过. 这里是用String pattern = "\\p{P}+"; 来过滤筛选出中英文符号. 代码例子: pr ...

  7. java判断数字大小写_java判断字符串是否全部由数字,大小写字母,特殊符号组成...

    直接上代码,经过验证. package javaTest; import java.util.regex.Matcher; import java.util.regex.Pattern; public ...

  8. java 字符长度 中文_java判断中文字符串长度的简单实例

    话不多说,上代码: /** * 获取字符串的长度,如果有中文,则每个中文字符计为2位 * @param value 指定的字符串 * @return 字符串的长度 */ public static i ...

  9. java判断字符长度_java判断中文字符串长度的简单实例

    话不多说,上代码: /** * 获取字符串的长度,如果有中文,则每个中文字符计为2位 * @param value 指定的字符串 * @return 字符串的长度 */ public static i ...

最新文章

  1. openstack 同一网络 多个subnet
  2. 原创Kafka学习笔记,java如何用数组生成随机数
  3. C和指针 (pointers on C)——第七章:函数(上)
  4. 数字证书文件格式(cer和pfx)的区别
  5. 《Ray Tracing in One Weekend》——Chapter 12: What's next?
  6. flask的各种装饰器
  7. 七种机器内部排序的原理与C语言实现,并计算它们的比较次数与移动次数。
  8. VB脚本:快速入门教程
  9. python微信所有代码_只需7行Python代码玩转微信自动聊天
  10. 八字 十二长生 详解
  11. 纸带打点计算机是什么原理,从电火花打点计时器高清拆解图,分析构造,详细解读电路工作原理...
  12. java学习路线(阿里p6)
  13. python写文件字母_Python - 文件读写
  14. CentOS 7 安装搜狗拼音输入法
  15. IDEA快捷键 进行查找和批量替换
  16. 小程序textarea字体错位
  17. 测试部门KPI考核指标(绩效考核)
  18. 基于Lucas-Kanade算法的三维光流提取matlab仿真
  19. 基于SNMP的信息刺探扫描与防护策略
  20. SR-GNN论文解读并附代码分析

热门文章

  1. 『杭电1410』PK武林盟主
  2. 特斯拉做工问题太多,但为何不影响大卖
  3. 北京丰面颊多长时间能恢复【咨询脂肪专家王明利博士】
  4. 霍尼韦尔官宣,世界最强量子计算机正式发布
  5. 即时通讯音视频解决方案 音视频技术处理
  6. 【故障诊断】用于轴承故障诊断的性能增强时变形态滤波方法及用于轴承断层特征提取的增强数学形态算子研究(Matlab代码实现)
  7. 能用android做什么管理系统,Android设备Root以后可以做些什么?
  8. WebLogic 重置域控制台账号密码
  9. 3060显卡和2080s显卡总掉卡,打开显卡的持续模式 nvidia-smi -pm 1
  10. CSS中奇数选择器与偶数选择器,一句代码怎么实现?