Android 汉字转拼音工具

  • 前言
  • 工具
  • 使用

前言

没有。。

工具

pinyin4j - 下载1
pinyin4j - 下载2

使用

import net.sourceforge.pinyin4j.PinyinHelper;
import net.sourceforge.pinyin4j.format.HanyuPinyinCaseType;
import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat;
import net.sourceforge.pinyin4j.format.HanyuPinyinToneType;
import net.sourceforge.pinyin4j.format.HanyuPinyinVCharType;
import net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombination;public class PinyinUtils {/*** 将字符串中的中文转化为拼音,其他字符不变* @param inputString* @return*/public static String getPinYin(String inputString){HanyuPinyinOutputFormat format = new HanyuPinyinOutputFormat();format.setCaseType(HanyuPinyinCaseType.LOWERCASE);format.setToneType(HanyuPinyinToneType.WITHOUT_TONE);format.setVCharType(HanyuPinyinVCharType.WITH_V);char[] input = inputString.trim().toCharArray();String outPut = "";try {for (char curchar : input){if (Character.toString(curchar).matches("[\\u4E00-\\u9FA5]+")){String[] temp = PinyinHelper.toHanyuPinyinStringArray(curchar, format);outPut += temp[0];}else {outPut += Character.toString(curchar);}}} catch (BadHanyuPinyinOutputFormatCombination badHanyuPinyinOutputFormatCombination) {badHanyuPinyinOutputFormatCombination.printStackTrace();}return outPut;}/*** 汉字转换为汉语拼音首字母,英文字符不变* @param chinese* @return*/public static String getFirstSpell(String chinese){StringBuffer pybf = new StringBuffer();char[] arr = chinese.toCharArray();HanyuPinyinOutputFormat defaultFormat = new HanyuPinyinOutputFormat();defaultFormat.setCaseType(HanyuPinyinCaseType.LOWERCASE);defaultFormat.setToneType(HanyuPinyinToneType.WITHOUT_TONE);for (char curchar : arr){if (curchar > 128){try {String[] temp = PinyinHelper.toHanyuPinyinStringArray(curchar, defaultFormat);if (temp != null) {pybf.append(temp[0].charAt(0));}} catch (BadHanyuPinyinOutputFormatCombination e) {e.printStackTrace();}}else {pybf.append(curchar);}}return pybf.toString().replaceAll("\\W", "").trim();}
}

Android 汉字转拼音工具相关推荐

  1. android 汉字转拼音pinyin4j包

    android 汉字转拼音pinyin4j包 转载于:https://www.cnblogs.com/longhs/p/3148276.html

  2. Java汉字转换拼音工具类

    1. 使用pinyin4j 1.1 引入相关maven依赖 <dependency><groupId>com.belerweb</groupId><artif ...

  3. 汉字转拼音(工具类)

    2019独角兽企业重金招聘Python工程师标准>>> package com.qst.tesc.course.web.rest.util; import java.io.Unsup ...

  4. Java汉字转为拼音工具类

    依赖文件 <!-- https://mvnrepository.com/artifact/com.belerweb/pinyin4j --><dependency><gr ...

  5. 汉字转拼音工具类,依赖Pinyin4J

    汉字转拼音工具类,依赖Pinyin4J Maven 坐标 <dependency><groupId>com.belerweb</groupId><artifa ...

  6. java汉字转拼音工具类源代码

    原文:java汉字转拼音工具类源代码 源代码下载地址:http://www.zuidaima.com/share/1550463387880448.htm 汉字转拼音 Pinyin pinyin = ...

  7. 能处理姓氏异读的汉字转拼音工具:hanz2piny

    hanz2piny 是一个汉字转拼音的工具,它高效.易用.无需单独数据文件,非常适合用于制作密码攻击的帐号字典,因为 hanz2piny 能处理姓氏异读. https://github.com/yan ...

  8. 汉字转拼音工具JPinyin的介绍和使用示例

    2019独角兽企业重金招聘Python工程师标准>>> 汉字转拼音的开源工具类包,已经出现过好几个,比如:Pinyin4J.Jpinyin等.本文主要结合JPinyin汉字转拼音的J ...

  9. java 汉字转拼音工具_java汉字转拼音工具类

    public classPinYinUtils {public staticHanyuPinyinOutputFormat PINYIN_FORMAT;static{ PINYIN_FORMAT= n ...

最新文章

  1. 电子学会青少年编程等级考试四级题目解析07
  2. Thread的start()和join()方法
  3. ExcelAndJSON的设计决策
  4. Socket套接字的速率控制(linux)
  5. android 调用java接口_android调用java的web service接口
  6. mysql增量脚本_mysql全量和增量备份脚本
  7. java设置默认参数_关于java:如何设置默认方法参数值?
  8. oracle索引可以加到in,为什么你加的索引不管用?
  9. 四川职称计算机英语,四川职称计算机考试报名细则
  10. 35行的山寨版jQuery
  11. 【UOJ#177】欧拉回路
  12. 国家地区代号与英文名对应表
  13. 数学连乘和累加运算符号_数学运算符号
  14. Pandas学习-练习题
  15. 流媒体视频播放代码总结。
  16. 问卷设计一:问卷题目哪些有类型和注意要点?
  17. 如何使用Python从视频中提取图像?(帧提取)详细代码实现
  18. java 读取xls、xlsx文件
  19. 某电子订单系统升级步骤
  20. OpenCV 图像处理 计算机视觉 深度学习 优秀博主推荐

热门文章

  1. dede taglist模板中调用自定义字段
  2. 40G以太网光模块解决方案
  3. 常用的一句话反弹shell总结
  4. NSSCTF web学习
  5. iphone同步android短信,如何从iPhone导入短信到Android手机?
  6. java中关于包的描述_下列关于Java包的描述中,错误的是() (1.0分)_学小易找答案
  7. root高级权限怎么弄,root高级权限怎么打开
  8. C语言程序设计(二)基础内容
  9. 华为云微认证考试简介
  10. 详解利用基于gensim的TF-IDF算法实现基于文本相似度的推荐算法