Android 汉字转拼音工具
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 汉字转拼音工具相关推荐
- android 汉字转拼音pinyin4j包
android 汉字转拼音pinyin4j包 转载于:https://www.cnblogs.com/longhs/p/3148276.html
- Java汉字转换拼音工具类
1. 使用pinyin4j 1.1 引入相关maven依赖 <dependency><groupId>com.belerweb</groupId><artif ...
- 汉字转拼音(工具类)
2019独角兽企业重金招聘Python工程师标准>>> package com.qst.tesc.course.web.rest.util; import java.io.Unsup ...
- Java汉字转为拼音工具类
依赖文件 <!-- https://mvnrepository.com/artifact/com.belerweb/pinyin4j --><dependency><gr ...
- 汉字转拼音工具类,依赖Pinyin4J
汉字转拼音工具类,依赖Pinyin4J Maven 坐标 <dependency><groupId>com.belerweb</groupId><artifa ...
- java汉字转拼音工具类源代码
原文:java汉字转拼音工具类源代码 源代码下载地址:http://www.zuidaima.com/share/1550463387880448.htm 汉字转拼音 Pinyin pinyin = ...
- 能处理姓氏异读的汉字转拼音工具:hanz2piny
hanz2piny 是一个汉字转拼音的工具,它高效.易用.无需单独数据文件,非常适合用于制作密码攻击的帐号字典,因为 hanz2piny 能处理姓氏异读. https://github.com/yan ...
- 汉字转拼音工具JPinyin的介绍和使用示例
2019独角兽企业重金招聘Python工程师标准>>> 汉字转拼音的开源工具类包,已经出现过好几个,比如:Pinyin4J.Jpinyin等.本文主要结合JPinyin汉字转拼音的J ...
- java 汉字转拼音工具_java汉字转拼音工具类
public classPinYinUtils {public staticHanyuPinyinOutputFormat PINYIN_FORMAT;static{ PINYIN_FORMAT= n ...
最新文章
- 电子学会青少年编程等级考试四级题目解析07
- Thread的start()和join()方法
- ExcelAndJSON的设计决策
- Socket套接字的速率控制(linux)
- android 调用java接口_android调用java的web service接口
- mysql增量脚本_mysql全量和增量备份脚本
- java设置默认参数_关于java:如何设置默认方法参数值?
- oracle索引可以加到in,为什么你加的索引不管用?
- 四川职称计算机英语,四川职称计算机考试报名细则
- 35行的山寨版jQuery
- 【UOJ#177】欧拉回路
- 国家地区代号与英文名对应表
- 数学连乘和累加运算符号_数学运算符号
- Pandas学习-练习题
- 流媒体视频播放代码总结。
- 问卷设计一:问卷题目哪些有类型和注意要点?
- 如何使用Python从视频中提取图像?(帧提取)详细代码实现
- java 读取xls、xlsx文件
- 某电子订单系统升级步骤
- OpenCV 图像处理 计算机视觉 深度学习 优秀博主推荐