中文转换为全拼和首字母
来源:百度文库 编辑:神马文学网 时间:2024/04/29 09:02:39
public class CnToPy {
//将汉字转换为全拼
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 {
//判断是否为汉字字符
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// System.out.println(Integer.toHexString(bGBK[i]&0xff));
strBuf.append(Integer.toHexString(bGBK[i]&0xff));
}
return strBuf.toString();
}
public static void main(String[] args) {
String cnStr = "中华人民共和国";
System.out.println(getPingYin(cnStr));
System.out.println(getPinYinHeadChar(cnStr));
}
}
下面为结果:
zhonghuarenmingongheguo
zhrmghg
//将汉字转换为全拼
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
//判断是否为汉字字符
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
strBuf.append(Integer.toHexString(bGBK[i]&0xff));
}
return strBuf.toString();
}
public static void main(String[] args) {
String cnStr = "中华人民共和国";
System.out.println(getPingYin(cnStr));
System.out.println(getPinYinHeadChar(cnStr));
}
}
下面为结果:
zhonghuarenmingongheguo
zhrmghg
中文转换为全拼和首字母
Excel 汉字转拼首字母
中文转换成拼音和笔画
C#中文和UNICODE编码互相转换1
中文转换成拼音
PDF和CAL格式如何转换为WORD格式2
☆★给汉字加拼音-中文句子转换为拼音-汉字与拼音的转换-汉字翻译为拼音-上海语翼翻译☆★
FLASH转换为视频格式
QQ个性签名,繁体字网名转换,最全的非主流个性签名和QQ网名
asp代码---------中文转换成utf
中文字号转换成英文的字号
中文字号转换成英文的字号
极坐标转换为直角坐标
直角坐标转换为极坐标
Word转换为PPT文稿
java文字转换为图片
Word快速转换为PPT
快速转换为PPT文稿
Word转换为PPT文稿
Word转换为pdf文件!
火车票首字母含义
【0110汉化组荣誉出品】Best eBook v1.03简体中文汉化版 电子书转换和阅读软件 BWO智能手机中文网论坛
字符串和字符数组转换
BSTR、char*和CString转换