Пример #1
0
  /**
   * 汉字转换位汉语拼音,英文字符不变
   *
   * @param chines 汉字
   * @return 拼音
   */
  @SuppressWarnings("deprecation")
  public static String getPinyin(String chines) {
    String pinyinName = "";
    HanyuPinyinOutputFormat defaultFormat = new HanyuPinyinOutputFormat();
    defaultFormat.setCaseType(HanyuPinyinCaseType.UPPERCASE);
    defaultFormat.setToneType(HanyuPinyinToneType.WITHOUT_TONE);

    try {
      pinyinName = PinyinHelper.toHanyuPinyinString(chines, defaultFormat, "");
    } catch (BadHanyuPinyinOutputFormatCombination e) {

    }
    return pinyinName;
  }
Пример #2
0
 /**
  * 使用PinYin4j.jar将汉字转换为拼音
  *
  * @param chineseStr
  * @return
  * @throws Exception
  */
 @SuppressWarnings("deprecation")
 public String chineneToSpell(String chineseStr) throws Exception {
   return PinyinHelper.toHanyuPinyinString(chineseStr, spellFormat, "");
 }