本文整理匯總了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;
}