将汉语转换成拼音(全拼和缩写)
为什么80%的码农都做不了架构师?>>>
* author:qiaolei
* 2010-6-25上午11:44:21create
*/
package com.sucre;
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 ChineseToEnglish {
// 将汉字转换为全拼
public static String getPingYin(String src){
char[] t1 = null;
t1=src.toCharArray();
String[] t2 = new String[t1.length];
HanyuPinyinOutputFormat t3 = new HanyuPinyinOutputFormat();
t3.setCaseType(HanyuPinyinCaseType.LOWERCASE);
t3.setToneType(HanyuPinyinToneType.WITHOUT_TONE);
t3.setVCharType(HanyuPinyinVCharType.WITH_V);
String t4="";
int t0=t1.length;
try {
for ( int i=0;i<t0;i++)
{
//判断是否为汉字字符
if(java.lang.Character.toString(t1[i]).matches( "[\\u4E00-\\u9FA5]+"))
{
t2 = PinyinHelper.toHanyuPinyinStringArray(t1[i], t3);
t4+=t2[0];
}
else
t4+=java.lang.Character.toString(t1[i]);
}
// System.out.println(t4);
return t4;
}
catch (BadHanyuPinyinOutputFormatCombination e1) {
e1.printStackTrace();
}
return t4;
}
// 返回中文的首字母
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码
public static String getCnASCII(String cnStr)
{
StringBuffer strBuf = new StringBuffer();
byte[] bGBK = cnStr.getBytes();
for( int i=0;i <bGBK.length;i++){
// System.out.println(Integer.toHexString(bGBK[i]&0xff));
strBuf.append(Integer.toHexString(bGBK[i]&0xff));
}
return strBuf.toString();
}
System.out.println(getPingYin( "綦江县"));
System.out.println(getPinYinHeadChar( "綦江县"));
System.out.println(getCnASCII( "綦江县"));
}
qjx
f4ebbdadcfd8
本文出自 “乔磊的博客 学习 进步” 博客,请务必保留此出处http://sucre.blog.51cto.com/1084905/353603
转载于:https://my.oschina.net/sucre/blog/296346
将汉语转换成拼音(全拼和缩写)相关推荐
- python缩写转换成全拼_将汉语转换成拼音(全拼和缩写)
程序里面用到了开源的包,可以将汉语转成全拼或者缩写,代码如下: /** * author:qiaolei * 2010-6-25上午11:44:21create */ package com.sucr ...
- 将中文汉字转换成拼音(全拼)
using System.Globalization; using System.Text; using System.Text.RegularExpressions;/// <summary& ...
- C# 把汉字转换成拼音(全拼)
public static string ChineseToFullPinYin(string chinese){// 匹配中文字符Regex regex = new Regex("^[\u ...
- vba 全拼_EXCEL中直接把中文转换成拼音全拼
1. 第一种方法 : 打开 Excel- 江具 - > 宏 - > Viaual Basic 编辑器 在弹出来的窗口中对着 VBAproject 点右键 - > 插入 - > ...
- IOS系统自带方法将汉语转换成拼音
//汉字转换成拼音:系统自带方法 //创建字符串 NSString *str = @"邵亚启"; 1.桥接转换成C的字符串 CFStringRef aCFString = (__b ...
- c++ 汉语转换成拼音
ATL::CString CInstUIDlg::Convert(LPCTSTR lpChinese, BOOL bShort) { /// 定义拼音区编码数组 static int pyValue[ ...
- C#下汉字转换成拼音
因为一个开发需求需要把汉字转换成拼音,没想到还真的可以! 找了一个类,是别人整理的,默认情况下第一个字母是大写的.我这边需要都是小写的,可以按照自己情况进行实际的需求进行修改,比如有些时候只要首字母就 ...
- hive 转拼音udf_自定义UDF函数:将汉字转换成拼音
工作需求要讲汉字转换成拼音,自定义UDF函数 import net.sourceforge.pinyin4j.PinyinHelper; import net.sourceforge.pinyin4j ...
- 自定义UDF函数:将汉字转换成拼音
工作需求要讲汉字转换成拼音,自定义UDF函数 import net.sourceforge.pinyin4j.PinyinHelper; import net.sourceforge.pinyin4j ...
最新文章
- [昨花今拾]补记昨日
- UDP转TCP隧道工具udptunnel
- 汇编语言——十六进制数据前加0规则
- leetcode 1631. 最小体力消耗路径(并查集)
- [机器学习笔记] Note4--逻辑回归
- matlab语音信号处理实验_现代通信综合实验系统平台
- 《一本书》文字展示网站Typecho主题
- 【李宏毅2020 ML/DL】P24 Semi-supervised
- 分享一个通过项目管理师证书成功办理北京户口的励志经验
- 计算机关机快捷键是什么,win7关机快捷键是什么
- 使用GoldWave制作“淡入/淡出”效果
- android 跟屁虫 教程,鬼谷八荒跟屁虫使用方法指南介绍 鬼谷八荒好感度快速提升方法教程攻略...
- 远程IT运维的升级,“团队协作”
- 基于android手机实时监控ipcam视频之一:RTSP
- 实现内容自动撑开盒子
- FineReport的数据库
- 关于IP地址、网络号、主机号、子网掩码之间的关系
- linux虚拟网卡修改mac地址,Win10秘笈:两种方式修改网卡物理地址(MAC)
- 安装声卡驱动报错,代码:0xe0000246
- [兴趣-画画] 基础 1