中文轉 拼音字母 全拼 工具類

2021-09-02 13:11:42 字數 1724 閱讀 7511

什麼都不用說了  直接貼**:

package test;

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;

/** * 中文轉字母、拼音工具類

* 注意:依賴的jar包:pinyin4j-2.5.0.jar

* * @author wp dec 9, 2015 6:40:59 pm

* */

public class pinyinapi

/*** 得到中文的全拼

* @param str

* @return

*/public static string getpinyinfull(string str)

/*** 得到中文的首字母(大寫)

* @param str

* @return

*/public static string getpinyinfirstchar(string str)

/*** 聲調型別(no_tone:無聲調、num_tone:數字聲調、mark_tone:標記聲調-中文)

* */

public static enum tonetype

private static hanyupinyinoutputformat format = new hanyupinyinoutputformat();

/*** 提取每個漢字的全拼或者首字母

* * @param str 要轉換的字串

* @param isfull 是否轉全拼

* @param tone 聲調型別

* @param islow 是否轉小寫

* @param istrim 是否去除中間的空格

* @return

*/public static string getpinyin(string str, boolean isfull, tonetype tone, boolean islow, boolean istrim)

if(islow)else

if(tonetype.mark_tone.equals(tone)) else if(tonetype.num_tone.equals(tone)) else

stringbuilder sb = new stringbuilder();

boolean flag = false;

for (int i = 0; i < str.length(); i++) else

}else

}else

} catch (exception e)

}return sb.tostring();

}/**

* 判斷字串是否為空

*/private static boolean isnull(object strdata)

return false;

}}

自動化指令碼之 中文轉拼音字母

美術的資源檔案往往都是中文名字 我們做自動化工具 很多時候 生成的目標 不支援中文 轉成拼音。在程式中,也方便我們理解檔案對應的 使用方式 var pinyin require pinyin console.log pinyin 中心 zh ng x n console.log pinyin 中心 ...

中文轉拼音首字母

使用者商品名稱簡拼搜尋 namespace common business 1.5.66 漢字轉拼音類 class pinyin 中文字串轉拼音首字母 strchangepin 漢字轉拼音的首字母 get first letter 漢字轉拼音 str2py 獲取拼音對應ascll碼 pinyin p...

ES支援中文 全拼 拼音首字母搜尋

新建模板,便於後續建立索引,直接使用模板,省事方便 put template goods pinyin filter full pinyin filter char filter tokenizer analyzer ngramsearchanalyzer ikindexanalyzer iksea...