好久没有写博客了,期间在做桌面云,被要求保密哈。不过最近在写一个android程序,需要实现一个中英文混合排序。不说了,直接代码;
HanYuUtil.java
HanYuUtil.java
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 HanYuUtil {
/**
* 将单个字符(包括单个汉字或者单个英文字母)转换为小写字母
* @param c
* @return
*/
public String getCharacterPinYin(char c)
{
String[] pinyin=null;
HanyuPinyinOutputFormat format =new HanyuPinyinOutputFormat();
format.setCaseType(HanyuPinyinCaseType.LOWERCASE);
format.setToneType(HanyuPinyinToneType.WITHOUT_TONE);//汉字没有声调
format.setVCharType(HanyuPinyinVCharType.WITH_V);
try{