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;
/**
*
* @Description:将汉字转化为全拼
* @ClassName CnToSpell
* @author: QIXIAOWEI
* @Created 2014 2014年12月22日 下午3:04:28
*/
public class CnToSpell {
// 将汉字转换为全拼
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 temp = "";
String demo = "";
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;
}
}
for (int i = 0; i < convert.length(); i++) {// convert目前为小写首字母,下面是将小写首字母转化为大写
if (convert.charAt(i) >= 'a' && convert.charAt(i) <= 'z') {
temp = convert.substring(i, i + 1).toUpperCase();
demo += temp;
}
}
return demo;
}
// 将字符串转移为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();
}
public static void main(String[] args) {
String cnStr = "齐晓威";
System.out.println(getPingYin(cnStr));
System.out.println(getPinYinHeadChar(cnStr));
}
}
相关推荐
Java实现汉字转拼音功能,包括首字母和全拼,为大家减少时间,为此提供便捷。
将汉字转为全拼或返回拼音首字母(Oracle SQL语句)
java根据汉字获取全拼和首字母 的jar包,有需要可以下载下载下载下载下载下载下载下载下载
通过中文获取中文首字母、中文全拼, java ------pinyin4j-2.5.0.jar
汉字转换为全拼或者首字母形式,oracle使用的sql
通过excel提供的宏很好的可以将文字转换为拼音,可以首字母大写、全拼。通过Visual Basic新建一个模块来实现
汉字转拼音,可以大小写、全拼、首字母,注释清晰明了。修改好的发给大家学习学习
将汉字转换为全拼或首字母,oracle 默认返回汉字拼音的首字母,第二个参数不为空则返回全拼
在 pinyin.js 中有两种转换: 全拼转换 和 拼音首字母转换。全拼转换时可以使用不同的 汉字库js 得到你想要的带或不带声调的全拼。 拼音首字母转换则随便使用哪种汉字库js了。hz.js 汉字拼音带声调。如: 贝bèi 。 ...
--此函数默认返回汉字拼音的首字母,第二个参数不为空则返回全拼。 create or replace function f_getFirstOrFullSpell(p_cnStr In varchar2,p_sign In number default null) return varchar2 as lv_spell varchar2...
Oracle中进行汉字转换成拼音,通过参数不同可以返回拼音首字母或全拼: --调用方式: SELECT f_getSpell('江西') from dual; --返回 'jx' --SELECT f_getSpell('江西',0) from dual; --返回 'jiangxi'
java 汉字转化为全拼 汉字拼音转化 jdk1.4版本
汉字转换为全拼
oracle汉字转换成拼音首字母、全拼,各种转换类型比较齐全,oracle汉字转换五笔首字母链接https://blog.csdn.net/weixin_40912627/article/details/88710064
## 获取name字段的首字母和全拼 SELECT to_getPY(name),to_pinyin(name) FROM pingying ##根据首字母查询 SELECT * FROM pingying where getPY(name)="QZ" ##"QZ"是参数 ##pingying是表名 name是需要查询列的列名
C#将汉字转换成全拼的拼音
Java汉字转换为拼音工具类 汉字转换为拼音包括全拼、首字母缩写;全拼可计算出多音字。
oracle汉字转拼音 获得全拼、拼音首字母、拼音截取等