工具類封裝實戰(四)漢字拼音互相轉換

2021-10-18 02:26:54 字數 2266 閱讀 4475

public class phonetictranscriptionutil  else 

}} catch (badhanyupinyinoutputformatcombination e)

result.setdata(hanyupinyin);

return result;

}/**

* 取當前字串所有的首字母 且輸出為大寫 (數字 標點 字母轉換成本身)

** @param chineselanguage

* @return

*/public resultgetfirstlettersup(string chineselanguage)

/*** 取當前字串所有的字元首字母 且輸出為小寫 (數字 符號 字母轉換為本身)

** @param chineselanguage

* @return

*/public resultgetfirstletterslo(string chineselanguage)

/*** 取當前字串所有的字元首字母 且輸出為小寫 (數字 字母轉換為本身 符號去除)

** @param chineselanguage

* @return

*/public resultgetpinyinstring(string chineselanguage)

// 如果字元是數字,取數字

else if (str.matches("[0-9]+"))

// 如果字元是字母,取字母

else if (str.matches("[a-za-z]+"))

// 否則不轉換

else

}} catch (badhanyupinyinoutputformatcombination e)

result.setdata(hanyupinyin);

return result;

}/**

* 取字串第乙個漢字的第乙個字元為大寫(數字 字母 標點轉換為本身)

** @return string

* @throws

*/public resultgetfirstletter(string chineselanguage)

// 如果字元是數字,取數字

else if (str.matches("[0-9]+"))

// 如果字元是字母,取字母

else if (str.matches("[a-za-z]+")) else

} catch (badhanyupinyinoutputformatcombination e)

result.setdata(hanyupinyin);

return result;

}/**

* 取字串第乙個漢字的第乙個字元為小寫(數字 字母 標點轉換為本身)

** @return string

* @throws

*/public resultgetfirstlower(string chineselanguage)

// 如果字元是數字,取數字

else if (str.matches("[0-9]+"))

// 如果字元是字母,取字母

else if (str.matches("[a-za-z]+")) else

} catch (badhanyupinyinoutputformatcombination e)

result.setdata(hanyupinyin);

return result;

}/**

* getfirstletterslo,getfirstlettersup的實現方法

** @param chineselanguage

* @param casetype

* @return

*/public string getfirstletters(string chineselanguage, hanyupinyincasetype casetype)

// 如果字元是數字,取數字

else if (str.matches("[0-9]+"))

// 如果字元是字母,取字母

else if (str.matches("[a-za-z]+"))

// 否則不轉換

else

}} catch (badhanyupinyinoutputformatcombination e)

return hanyupinyin;

}}

漢字轉拼音工具類

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...

漢字轉拼音的工具類

介紹3個方法 漢字轉換為拼音 獲取每個漢字的首字母 獲取第乙個漢字的首字母 如果是姓名,即姓的首字母 如下 pinyinutil package com.home import net.sourceforge.pinyin4j.pinyinhelper import net.sourceforge....