- 浏览: 146881 次
- 性别:
- 来自: 深圳
文章分类
最新评论
-
lyaqys:
lz实现的OptimisticExclusiveLock有点问 ...
java park/unpark 【java并发】基于JUC CAS原理,自己实现简单独占锁
package com.open.sorce.pingying4j;
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 SuggestTest {
/**
* 将汉字转换为全拼
*
* @param src
* @return String
*/
public static String getPinYin(String src)
{
if(src == null || "".endsWith(src)) {
return "";
}
char[] words = src.toCharArray();
int wordCount = words.length;
String[] pinyin = new String[wordCount];
// 设置汉字拼音输出的格式
HanyuPinyinOutputFormat outputFormat = new HanyuPinyinOutputFormat();
outputFormat.setCaseType(HanyuPinyinCaseType.LOWERCASE);
outputFormat.setToneType(HanyuPinyinToneType.WITHOUT_TONE);
outputFormat.setVCharType(HanyuPinyinVCharType.WITH_V);
StringBuffer sb = new StringBuffer();
try
{
for (int i = 0; i < wordCount; i++)
{
// 判断能否为汉字字符
// System.out.println(t1[i]);
if (Character.toString(words[i]).matches("[\\u4E00-\\u9FA5]+"))
{
pinyin = PinyinHelper.toHanyuPinyinStringArray(words[i], outputFormat);// 将汉字的几种全拼都存到t2数组中
sb.append(pinyin[0]);// 取出该汉字全拼的第一种读音并连接到字符串t4后
}
else
{
// 如果不是汉字字符,间接取出字符并连接到字符串t4后
sb.append(Character.toString(words[i]));
}
}
}
catch (BadHanyuPinyinOutputFormatCombination e)
{
e.printStackTrace();
}
return sb.toString();
}
/**
* 提取每个汉字的首字母
*
* @param str
* @return String
*/
public static String getPinYinHeadChar(String str)
{
String convert = "";
for (int j = 0; j < str.length(); j++)
{
char word = str.charAt(j);
// 提取汉字的首字母
String[] pinyinArray = PinyinHelper.toHanyuPinyinStringArray(word);
if (pinyinArray != null)
{
convert += pinyinArray[0].charAt(0);
}
else
{
convert += word;
}
}
return convert;
}
/**
* 将字符串转换成ASCII码
*
* @param cnStr
* @return String
*/
public static String getCnASCII(String cnStr)
{
StringBuffer strBuf = new StringBuffer();
// 将字符串转换成字节序列
byte[] bGBK = cnStr.getBytes();
for (int i = 0; i < bGBK.length; i++)
{
// 将每个字符转换成ASCII码
strBuf.append(Integer.toHexString(bGBK[i] & 0xff));
}
return strBuf.toString();
}
public static void main(String[] args)
{
String cnStr = "陈光标a14-|*肖慧";
System.out.println(getPinYin(cnStr));
System.out.println(getPinYinHeadChar(cnStr));
System.out.println(getCnASCII(cnStr));
String[] words = {"abc","abc小花","李世民12a","王二小"};
for(String word : words) {
System.out.println(word.matches("[\\u4E00-\\u9FA5]+"));
}
}
}
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 SuggestTest {
/**
* 将汉字转换为全拼
*
* @param src
* @return String
*/
public static String getPinYin(String src)
{
if(src == null || "".endsWith(src)) {
return "";
}
char[] words = src.toCharArray();
int wordCount = words.length;
String[] pinyin = new String[wordCount];
// 设置汉字拼音输出的格式
HanyuPinyinOutputFormat outputFormat = new HanyuPinyinOutputFormat();
outputFormat.setCaseType(HanyuPinyinCaseType.LOWERCASE);
outputFormat.setToneType(HanyuPinyinToneType.WITHOUT_TONE);
outputFormat.setVCharType(HanyuPinyinVCharType.WITH_V);
StringBuffer sb = new StringBuffer();
try
{
for (int i = 0; i < wordCount; i++)
{
// 判断能否为汉字字符
// System.out.println(t1[i]);
if (Character.toString(words[i]).matches("[\\u4E00-\\u9FA5]+"))
{
pinyin = PinyinHelper.toHanyuPinyinStringArray(words[i], outputFormat);// 将汉字的几种全拼都存到t2数组中
sb.append(pinyin[0]);// 取出该汉字全拼的第一种读音并连接到字符串t4后
}
else
{
// 如果不是汉字字符,间接取出字符并连接到字符串t4后
sb.append(Character.toString(words[i]));
}
}
}
catch (BadHanyuPinyinOutputFormatCombination e)
{
e.printStackTrace();
}
return sb.toString();
}
/**
* 提取每个汉字的首字母
*
* @param str
* @return String
*/
public static String getPinYinHeadChar(String str)
{
String convert = "";
for (int j = 0; j < str.length(); j++)
{
char word = str.charAt(j);
// 提取汉字的首字母
String[] pinyinArray = PinyinHelper.toHanyuPinyinStringArray(word);
if (pinyinArray != null)
{
convert += pinyinArray[0].charAt(0);
}
else
{
convert += word;
}
}
return convert;
}
/**
* 将字符串转换成ASCII码
*
* @param cnStr
* @return String
*/
public static String getCnASCII(String cnStr)
{
StringBuffer strBuf = new StringBuffer();
// 将字符串转换成字节序列
byte[] bGBK = cnStr.getBytes();
for (int i = 0; i < bGBK.length; i++)
{
// 将每个字符转换成ASCII码
strBuf.append(Integer.toHexString(bGBK[i] & 0xff));
}
return strBuf.toString();
}
public static void main(String[] args)
{
String cnStr = "陈光标a14-|*肖慧";
System.out.println(getPinYin(cnStr));
System.out.println(getPinYinHeadChar(cnStr));
System.out.println(getCnASCII(cnStr));
String[] words = {"abc","abc小花","李世民12a","王二小"};
for(String word : words) {
System.out.println(word.matches("[\\u4E00-\\u9FA5]+"));
}
}
}
发表评论
-
libevent简单的http实现
2013-07-22 22:44 5541 #include <sys/types.h> ... -
atoi源码
2013-05-14 19:32 1226原文: http://blog.csdn.net/eroswa ... -
为重负网络优化 Nginx 和 Node.js
2013-05-13 01:12 955原文:http://linux.cn/forum.php?mo ... -
sphinx 遇见的问题
2013-04-16 14:54 9891>>index 'xxx': search er ... -
mysql 下载地址
2013-04-11 11:25 580http://mysql.ntu.edu.tw/Downloa ... -
sphinx 安装
2013-04-10 19:54 505[@zw-76-80 soft]$ rpm -ivh MySQ ... -
socket参数详解:KeepAlive
2013-03-19 13:24 1100TCP协议中有长连接和短连接之分。短连接在数据包发送完成后就会 ... -
ehcache分布式例子
2013-03-19 11:52 608配置文件: recluster_ehcache_0.xml ... -
tinyxml 实例
2013-02-28 15:00 606tinyxml 实例 例子见附件 -
git 使用
2013-01-23 18:24 533git status 查看文件的状态 git add src/ ... -
ehchahe 例子
2013-01-23 15:40 946package test; import net.sf.eh ... -
url
2012-12-23 11:25 533http://labs.gree.jp/Top/OpenSou ... -
common-pool
2012-12-11 19:09 748package com.open.sorce.common; ... -
apache.commons工具例子
2012-12-04 10:40 641import org.apache.commons.lang. ... -
apache.commons工具
2012-12-03 10:22 1001本文主要介绍自己在开发过程中总结的一些Java工具类,主要包括 ... -
guava-map
2012-11-29 11:38 783------------------------------- ... -
Jsoup
2012-11-21 17:28 971官网:http://jsoup.org/ jsoup 是一款 ...
相关推荐
C#汉字转拼音(npinyin)将中文转换成拼音全文或首字母
使用拼音4j将汉字转为拼音的代码及其pinyin4j的jar包
拼音转换成汉字的好工具 拼音转换成汉字的好工具
主要介绍了Mysql中文汉字转拼音的实现,并且每个汉字会转换全拼,使用Mysql自定义函数实现,需要的朋友可以参考下
网上传的postgreSQL汉字转拼音的方法,是针对9.3的版本(相信你要是8.4的也搜到了但不能直接用,才来看我的),尝试了8.4的版本来做拼音处理。发现网上的《postgreSQL汉字转拼音》里面坑比较多,尝试纠正了一下,发...
c#中将汉字转换成拼音,这个是在vs中开发的,方便大家参考学习
java汉字转拼音,android汉字转拼音,汉字转拼音首字母,汉字转ASCII
C++,采用“拼音-中文”的数据字典的方式实现中文汉字转拼音,兼容多音字,字典为txt,后期可拓展易维护。在STL的map中查找效率16毫秒左右。
SQL中将汉字转换成拼音,这里是转换汉字首拼音,如果需要全部转换,在以下程序中稍微改几个数字就可以了
支持2万+汉字转拼音
自定义函数,将汉字转换成每个汉语拼音的首字母
Delphi 成批将汉字转换为拼音码、五笔简码 Delphi 通过查询资源文件 wbtext.rec 得到编码,得到汉字的五笔、拼音编码 (支持 7500个简体、繁体汉字) 1、批量将汉字转换为拼音码、拼音简码、五笔码、五笔简码。 ...
''' 汉字转拼音 ''' 作者:小恶魔 ''' 出于:另一个世界 ''' Web :Arwd.Net ''' 版本:1.0.0.0 汉字转拼音 封装类,可直接调用Dll。
pinyin4J java拼音转换工具 java汉字转换拼音工具
php中文转换成拼音apiphp中文转换成拼音apiphp中文转换成拼音apiphp中文转换成拼音apiphp中文转换成拼音apiphp中文转换成拼音api
在很多地方都可以用的 这是一个通用的汉字转换拼音 只要写几换代码就可以了 说的再好也不如下个用用JAVA做的
简介:自己写的IDEA插件,可以将汉字转换为拼音缩写的插件,有需要的可以下载玩玩。 用法:下载之后正常进行插件安装,安装之后在Edit菜单里面会出现ChineseToPY选项,选中文字之后点击这个选项就可以将所选的文字...
.net汉字转换拼音
可以将汉字转换成拼音的asp源文件,什么文件无关紧要,关键是资源及转换的方法。
支持汉字转换拼音,汉字转换拼音缩写。其实程序没有什么,重点在于已经统计了大部分常用汉字