package com.shzg.project.worn.unit;

import net.sourceforge.pinyin4j.PinyinHelper;

public class PinyinUtils
{

    /**
     * 获取中文首字母
     */
    public static String getFirstLetter(String chinese)
    {
        StringBuilder sb = new StringBuilder();

        for (char c : chinese.toCharArray())
        {
            if (String.valueOf(c).matches("[\\u4E00-\\u9FA5]+"))
            {
                String[] pinyin = PinyinHelper.toHanyuPinyinStringArray(c);
                if (pinyin != null)
                {
                    sb.append(Character.toUpperCase(pinyin[0].charAt(0)));
                }
            }
            else
            {
                sb.append(c);
            }
        }

        return sb.toString();
    }

}