漢字轉拼音的工具類

2021-06-21 05:54:18 字數 1419 閱讀 7339

介紹3個方法:漢字轉換為拼音、獲取每個漢字的首字母、獲取第乙個漢字的首字母(如果是姓名,即姓的首字母),**如下:

pinyinutil:

package com.home;

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;

/** * 拼音轉換工具類

* * @author administrator

* */

public class pinyinutil else }}

} catch (badhanyupinyinoutputformatcombination e)

return output;

} /**

* 得到每個漢字首字母,英文本元不變

* * @param chinesestr

* @return

*/public static string getfirstspell(string chinesestr)

} catch (badhanyupinyinoutputformatcombination e)

} else

}} return sb.tostring().replaceall("\\w", "").trim();

} /**

* 獲取姓名中姓的首字母

* * @param chinesestr

* @param isupper

* 是否轉換為大寫字母

* @return

*/public static string getfirstletter(string chinesestr, boolean isupper) else

return firstletter;

}}

漢字轉拼音工具類

public class pinyin4jutils 將字串轉換成拼音陣列 param src return public static string stringtopinyin string src,string separator 將字串轉換成拼音陣列 param src param ispo...

漢字轉拼音工具類

package com.example.demo.utils import net.sourceforge.pinyin4j.pinyinhelper author suyanlong date created in 2020 6 30 14 18 description ceshi version...

漢字轉拼音類

using system using system.collections.generic using system.linq using system.web using system.text using system.text.regularexpressions 定義陣列 private s...