jar包:http://pan.baidu.com/s/11ikCY

import net.sourceforge.pinyin4j.PinyinHelper;
import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat;
import net.sourceforge.pinyin4j.format.HanyuPinyinToneType;
import net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombination; public class pinyin { public static void main(String[] args) {
System.out.println(new pinyin().Console('你'));
} public String Console(char order) {
HanyuPinyinOutputFormat format = new HanyuPinyinOutputFormat();
format.setToneType(HanyuPinyinToneType.WITHOUT_TONE);
String[] pinyinArray = null;
try {
pinyinArray = PinyinHelper.toHanyuPinyinStringArray(order, format);
} catch (BadHanyuPinyinOutputFormatCombination e) {
e.printStackTrace();
} if (pinyinArray!=null) {
return pinyinArray[0];
} else {
return order + "";
}
}
}

利用pingyin4j 将汉字转换为拼音的更多相关文章

  1. JAVA实现汉字转换为拼音 pinyin4j/JPinyin

    在项目中经常会遇到需求用户输入汉字后转换为拼音的场景,比如说通讯录,就会要求按名字首字符发音排序,如果自己写实现这方面的功能是个很好大的工程,还好网上有公开的第三方jar支持转换,结合网上很多前辈的代 ...

  2. iOS将汉字转换为拼音

    将汉字转换为拼音 - (NSString *)chineseToPinyin:(NSString *)chinese withSpace:(BOOL)withSpace { CFStringRef h ...

  3. 使用PinYin4j.jar将汉字转换为拼音

    package com.Test.util; import net.sourceforge.pinyin4j.PinyinHelper; import net.sourceforge.pinyin4j ...

  4. 使用CFStringTransform将汉字转换为拼音

    之前做通讯录相关的一些App时,有一个比较常用的算法是将汉字转换成拼音.当时采用的做法是:将各个拼音段的首个汉字(按Unicode排序)做成两个数组,一个数组存拼音,另一个数组存拼音对应首个汉字的Un ...

  5. sql函数:汉字转换为拼音

    sql数据库自定义一个函数把下面代码写进去 功能是得到汉字拼音首字母create function fun_getPY(@str nvarchar(4000)) returns nvarchar(40 ...

  6. 汉字转换为拼音的JavaScript库

    将JSPinyin剥离mootools这个JavaScript库,可以独立使用. 1)一个是将汉字翻译为拼音,其中每一个字的首字母大写: pinyin.getFullChars(this.value) ...

  7. js汉字转换为拼音

    片段 1 片段 2 gistfile1.txt /* --- description: Pinyin, to get chinese pinyin from chinese. license: MIT ...

  8. C#实现汉字转换为拼音缩写的代码

    using System; using System.Configuration; using System.Data; using System.Web; using System.Web.Secu ...

  9. php将汉字转换为拼音和得到词语首字母(一)

    <?php /** * 修复二分法查找方法 * 汉字拼音首字母工具类 * 注: 英文的字串:不变返回(包括数字) eg .abc123 => abc123 * 中文字符串:返回拼音首字符 ...

随机推荐

  1. 坚持不懈之linux haproxy的配置文件关键字查询手册

    1.关键词balance balance用于定义负载均衡的算法,可用于defaults.listen和backend中. balance使用方法如下: balance <algorithm> ...

  2. linux expect 简单讲解

    来自http://blog.csdn.net/winstary/archive/2009/08/08/4422156.aspx使用expect实现自动登录的脚本,网上有很多,可是都没有一个明白的说明, ...

  3. FastCgi与PHP-fpm之间是个什么样的关系

    刚开始对这个问题我也挺纠结的,看了<HTTP权威指南>后,感觉清晰了不少. 首先,CGI是干嘛的?CGI是为了保证web server传递过来的数据是标准格式的,方便CGI程序的编写者. ...

  4. PHP 冒泡原理

    header('Content-Type: text/html; charset=utf-8'); // 简单冒泡算法 $a = array(5,43,3,2,1); function mp($a){ ...

  5. RabbitMQ消息队列:ACK机制

    每个Consumer可能需要一段时间才能处理完收到的数据.如果在这个过程中,Consumer出错了,异常退出了,而数据还没有处理完成,那么 非常不幸,这段数据就丢失了. 因为我们采用no-ack的方式 ...

  6. scp失效问题

    1.症状 (1)登陆到服务器A(已在本机用ssh-add, ssh -A),scp 到服务器B时提示public key有问题: (2)/tmp/下没有ssh-XXX目录 2.原因 服务器A被pupp ...

  7. Java for LeetCode 149 Max Points on a Line

    Given n points on a 2D plane, find the maximum number of points that lie on the same straight line. ...

  8. 【JAVA、C++】LeetCode 014 Longest Common Prefix

    Write a function to find the longest common prefix string amongst an array of strings. 解题思路: 老实遍历即可, ...

  9. POJ 3977

    Subset Time Limit: 30000MS   Memory Limit: 65536K Total Submissions: 1373   Accepted: 228 Descriptio ...

  10. 爱情之路(codevs 2070)

    题目描述 Description yh非常想念他的女朋友小y,于是他决定前往小y所在的那块大陆. 小y所在的大陆共有n个城市,m条双向路,每条路连接一个或两个城市.经过一条路ei需要耗费时间ti.此外 ...