Java汉字转拼音
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.exception.BadHanyuPinyinOutputFormatCombination; public class Test { public static void main(String[] args) {
String input = "汉字转拼音"; // 创建汉语拼音处理类
HanyuPinyinOutputFormat defaultFormat = new HanyuPinyinOutputFormat();
// 输出设置,大小写,音标方式
defaultFormat.setCaseType(HanyuPinyinCaseType.LOWERCASE); defaultFormat.setToneType(HanyuPinyinToneType.WITHOUT_TONE);
// HanyuPinyinToneType.WITHOUT_TONE//无声调表示
// HanyuPinyinToneType.WITH_TONE_MARK//声调符号表示
// HanyuPinyinToneType.WITH_TONE_NUMBER//声调数字表示 char [] input_char = input.toCharArray();
String []pinyingStr = new String[input.length()];
StringBuffer out = new StringBuffer();
for(int i=0;i<input.length();i++){
try {
pinyingStr = PinyinHelper.toHanyuPinyinStringArray(input_char[i],defaultFormat);
out.append(pinyingStr[0]);
} catch (BadHanyuPinyinOutputFormatCombination e) {
e.printStackTrace();
}
} System.out.println(out);
}
}
项目比较简单,主要是用来学习下,如果要开发的话需要看项目具体功能具体分析。。。
使用jar包:pinyin4j-2.5.0.jar,需要jar包的可以百度下
Java汉字转拼音的更多相关文章
- java汉字转拼音以及得到首字母通用方法
package oa.common.utils; import net.sourceforge.pinyin4j.PinyinHelper; import net.sourceforge.piny ...
- [转]Java汉字按照拼音排序
最近项目上使用到汉字排序的问题,网上搜索了一下后普遍使用下面的方法比较. @Test public void test_sort_pinyin() { Collator cmp = Collator. ...
- java 汉字转拼音
先决条件: pinyin4j.jar(Pinyin4j是一个流行的Java库,支持中文字符和拼音之间的转换.拼音输出格式可以定制.) 下载地址:http://pan.baidu.com/share/l ...
- java汉字转拼音的工具类
import com.google.common.base.Strings;import net.sourceforge.pinyin4j.PinyinHelper;import net.source ...
- Android Java汉字转拼音总结
转载请表明出处:http://blog.csdn.net/lmj623565791/article/details/23187701 开发过程中有时候会遇到使用拼音模糊搜索等功能(典型的就是Andro ...
- JAVA汉字转拼音(取首字母大写)
import net.sourceforge.pinyin4j.PinyinHelper;import net.sourceforge.pinyin4j.format.HanyuPinyinCaseT ...
- 用jpinyin实现汉字转拼音功能
一.简介 项目地址:https://github.com/stuxuhai/jpinyin JPinyin是一个汉字转拼音的Java开源类库,在PinYin4j的功能基础上做了一些改进. [JPiny ...
- 汉字转拼音开源工具包Jpinyin介绍
最近要实现一个根据词语得到词语对应拼音的功能,找到了Jpinyin这个开源工具包,使用下来发现它非常强大,完全满足我的需求,下面对它做一个简单的介绍,希望能够帮助到有需要的朋友. https://gi ...
- java实现将汉字转为拼音
有时候为了方便操作程序的开发,需要将汉字转为拼音等操作.下面这个是自己结合网上的资料,加上自己在公司项目中的亲自实践.完整的实现了将汉字转为拼音的操作.这个Demo只是负责将其转换,在main方法中测 ...
随机推荐
- C#遍历集合与移除元素的方法
如果用foreach,会造成被遍历的集合更改后带来异常问题. 此时,用for循环可有效的解决这个问题. for(int i=0;i<List.Count;i++) { if(条件是真) { Li ...
- web.xml常用元素配置
tomcat服务器: tomcat是一个WEB服务器,所有的j2ee WEB程序可以在此处运行. tomcat服务器是一个符合j2ee标准的WEB服务器.则J2ee的EJB程序无法在此处运行. 如果要 ...
- 初学Python之异步多线程:sockserver
异步多线程:服务端 import socketserver class MyServer(socketserver.BaseRequestHandler): def setup(self): pass ...
- jquery 使用方法(二)
jquery語法: jquery語法是為html元素的选取编制的,可以对元素执行某些操作. 基础语法是:$(selector).action() 美元符号定义 jQuery 选择符(selector) ...
- python3.5-day5_迭代器_生成器_装饰器_模块
笔者QQ 360212316 迭代器&生成器 生成器: 一个函数调用返回一个迭代器,那这个函数叫做生成器,如果函数中包含yield语法,那么这个函数就会变成生成器 生成器的特点: 1.生成器必 ...
- EntityFramework Reverse POCO Generator工具
https://visualstudiogallery.msdn.microsoft.com/ee4fcff9-0c4c-4179-afd9-7a2fb90f5838
- JavaScript DOM编程艺术读书笔记(一)
第一章,第二章 DOM:是一套对文档的内容进行抽象和概念化的方法. W3C中的定义:一个与系统平台和编程语言无关的接口,程序和脚本可以通过这个接口动态的访问和修改文档的内容,结构和样式. DHTML( ...
- js中原型继承的三种方式
- asp.net LINQ防止SQL注入式攻击
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.We ...
- CSS3 background-size 属性
http://www.w3school.com.cn/cssref/pr_background-size.asp