本文整理汇总了Java中net.sourceforge.pinyin4j.PinyinHelper.toHanyuPinyinString方法的典型用法代码示例。如果您正苦于以下问题:Java PinyinHelper.toHanyuPinyinString方法的具体用法?Java PinyinHelper.toHanyuPinyinString怎么用?Java PinyinHelper.toHanyuPinyinString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.sourceforge.pinyin4j.PinyinHelper
的用法示例。
在下文中一共展示了PinyinHelper.toHanyuPinyinString方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: processMessageString
import net.sourceforge.pinyin4j.PinyinHelper; //导入方法依赖的package包/类
/**
* Sends alerts to the Pebble watch, as per the Pebble app's intents
* @param alert Alert which to send to the watch.
*/
private static String processMessageString(String originalMessage) {
// This is the traditional Pebble alert which does not show Unicode characters
HanyuPinyinOutputFormat format = new HanyuPinyinOutputFormat();
format.setCaseType(HanyuPinyinCaseType.LOWERCASE);
format.setToneType(HanyuPinyinToneType.WITH_TONE_NUMBER);
format.setVCharType(HanyuPinyinVCharType.WITH_V);
try {
// I know this is deprecated but there's no viable alternative...
return PinyinHelper.toHanyuPinyinString(originalMessage, format , "");
} catch (BadHanyuPinyinOutputFormatCombination e) {
Log.e("Pinyin", "Failed to convert pinyin");
}
return "";
}
示例2: getPinYin
import net.sourceforge.pinyin4j.PinyinHelper; //导入方法依赖的package包/类
/**
* 传入要分析的上行词,全拼解析,只解析汉字,英文,数字
*
* @param word
* @return
*/
public static String getPinYin(String word) {
char[] ch = word.trim().toCharArray();
StringBuilder rs = new StringBuilder();
try {
if (ch.length > 40) {
return PinyinHelper.toHanyuPinyinString(word, format, " ");
}
// 解析
String s_ch;
String[] temp;
for (int i = 0; i < ch.length; i++) {
s_ch = Character.toString(ch[i]);
if (s_ch.matches("[\u4e00-\u9fa5]+")) {
// 汉字
temp = PinyinHelper.toHanyuPinyinStringArray(ch[i], format);
if (null != temp && temp.length > 0) {
rs.append(temp[0]);
}
} else if (s_ch.matches("[\u0030-\u0039]+")) {
// 0-9
rs.append(s_ch);
} else if (s_ch.matches("[\u0041-\u005a]+") || s_ch.matches("[\u0061-\u007a]+")) {
// a-zA-Z
rs.append(s_ch);
}
}
} catch (BadHanyuPinyinOutputFormatCombination e) {
e.printStackTrace();
}
return rs.toString();
}
示例3: getPinyin
import net.sourceforge.pinyin4j.PinyinHelper; //导入方法依赖的package包/类
/**
* 将指定字符串转为拼音
*
* @param source 字符串
* @param sep 每个汉字拼音之间的分隔符
* @return 拼音。英文字符不变。多个汉字的拼音之间用指定的字符分隔
*/
@SuppressWarnings("deprecation")
public static String getPinyin(String source,String sep){
try {
return PinyinHelper.toHanyuPinyinString(source, FORMAT_DEFAULT, sep);
} catch (BadHanyuPinyinOutputFormatCombination e) {
throw new IllegalArgumentException(e.getMessage());
}
}
示例4: Pinyin4j_StringToPinyin
import net.sourceforge.pinyin4j.PinyinHelper; //导入方法依赖的package包/类
@Benchmark
public void Pinyin4j_StringToPinyin() throws BadHanyuPinyinOutputFormatCombination {
PinyinHelper.toHanyuPinyinString(inputStr, format, ",");
}
示例5: hanziToPinyin
import net.sourceforge.pinyin4j.PinyinHelper; //导入方法依赖的package包/类
/**
*
* 将汉字转换成拼音
*
* @param hanzi
*
* @param separator
*
* @return
*/
@SuppressWarnings("deprecation")
public static String hanziToPinyin(String hanzi, String separator) {
// 创建汉语拼音处理类
HanyuPinyinOutputFormat defaultFormat = new HanyuPinyinOutputFormat();
// 输出设置,大小写,音标方式
defaultFormat.setCaseType(HanyuPinyinCaseType.LOWERCASE);
defaultFormat.setToneType(HanyuPinyinToneType.WITHOUT_TONE);
String pinyingStr = "";
try {
pinyingStr = PinyinHelper.toHanyuPinyinString(hanzi, defaultFormat,
separator);
} catch (BadHanyuPinyinOutputFormatCombination e) {
e.printStackTrace();
}
return pinyingStr;
}