中文轉拼音 中英文首字母提取

2021-09-02 07:15:44 字數 1551 閱讀 7953

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;

public class pinyin4jutil

}return sb.tostring();

}/**

* 將字串(中文,英文,標點)轉為拼音. 中文轉為拼音,英文去除空格小寫,標點被忽略.

* * @param input

* @return

* @throws badhanyupinyinoutputformatcombination

*/public static string comperss(string input) throws badhanyupinyinoutputformatcombination else }}

return sb.tostring();

}/**

* 判斷字元是否為中文

* * @param word

* @return

*/public static boolean checkchinese(char word)

/*** 將單個字元轉為拼音

* * @param input

* @return

* @throws badhanyupinyinoutputformatcombination

*/public static string topinyin(char input) throws badhanyupinyinoutputformatcombination

return sb.tostring();

}/**

* 取中文和英文首字母,數字等

*/public static string getfirstletter(string chineselanguage)

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

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

} else }

} catch (badhanyupinyinoutputformatcombination e) }

return hanyupinyin.tostring(); }

}需要匯入jar包 : pinyin4j-2.5.0.jar

java中英文獲取首字母

package com.ijushang.shop.util author shiyz creation date 2012 10 25 上午11 01 34 public class getpinyin public getpinyin 字母z使用了兩個標籤,這裡有 個值 i,u,v都不做聲母,跟...

mysql中英文拼音首字母獲取及排序

在資料庫中需要根據使用者名稱按a z排序 因為我們通常使用的編碼都是utf 8 所以直接排序並不是按照我們所期待的拼音從a z排序 我們需要將字元轉換成gbk即可 select from tb user order byconvert tb user.name using gbk 這種方式可以簡單粗...

中文轉拼音首字母

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