All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.gitee.yongzhuzl.commonutil.util.pinyin.PinyinUtil Maven / Gradle / Ivy

Go to download

commonutil是一个功能丰富的Java工具类库,通过封装静态方法,降低学习成本,提升工作效率。

There is a newer version: 4.4.8
Show newest version
package com.gitee.yongzhuzl.commonutil.util.pinyin;

import net.sourceforge.pinyin4j.PinyinHelper;

/**
 * description: 拼音相关工具类
 * @author 朱正磊
 * @date 2021-08-27 13:04:29
 */
@SuppressWarnings("ALL")
public class PinyinUtil {

    /**
     * description: 获取中文字符串大写首字母,比如:清华大学 -> QHDX
     * @author 朱正磊
     * @date 2021-08-27 11:51:12
     * @param content 需要转化的中文字符串
     * @return 返回大写首字母缩写的字符串
     */
    public static String getPinYinHeadChar(String content) {
        StringBuilder convert = new StringBuilder();
        for (int i = 0; i < content.length(); i++) {
            char word = content.charAt(i);
            String[] pinyinArray = PinyinHelper.toHanyuPinyinStringArray(word);
            if (pinyinArray != null) {
                convert.append(pinyinArray[0].charAt(0));
            } else {
                convert.append(word);
            }
        }
        return convert.toString().toUpperCase();
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy