|
|
@ -1,5 +1,6 @@ |
|
|
|
package com.yxt.common.base.utils; |
|
|
|
|
|
|
|
import cn.hutool.extra.pinyin.PinyinUtil; |
|
|
|
import lombok.AllArgsConstructor; |
|
|
|
import lombok.Data; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
@ -170,9 +171,11 @@ public class HanZiConverterPinYin { |
|
|
|
firstString = Character.toString(firstChar).toUpperCase(); |
|
|
|
} |
|
|
|
|
|
|
|
String code = hanZiConverterPinYin.getHanZiPY(str); |
|
|
|
// String code = hanZiConverterPinYin.getHanZiPY(str);
|
|
|
|
String code = PinyinUtil.getFirstLetter(str, ""); |
|
|
|
StringBuffer buffer = new StringBuffer(code); |
|
|
|
code = buffer.replace(0, 1, firstString).toString(); |
|
|
|
code = code.toUpperCase(); |
|
|
|
System.out.println(code); |
|
|
|
return code; |
|
|
|
} |
|
|
@ -180,7 +183,7 @@ public class HanZiConverterPinYin { |
|
|
|
//测试
|
|
|
|
public static void main(String[] args) { |
|
|
|
HanZiConverterPinYin hanZiConverterPinYin = new HanZiConverterPinYin(); |
|
|
|
String str = "仇闪"; |
|
|
|
String str = "王佳琪"; |
|
|
|
char firstChar = str.toCharArray()[0]; |
|
|
|
String firstString = ""; |
|
|
|
if (Character.toString(firstChar).matches("^[\u4e00-\u9fa5]+$")) { // 为中文
|
|
|
@ -196,9 +199,11 @@ public class HanZiConverterPinYin { |
|
|
|
firstString = Character.toString(firstChar).toUpperCase(); |
|
|
|
} |
|
|
|
|
|
|
|
String code = hanZiConverterPinYin.getHanZiPY(str); |
|
|
|
// String code = hanZiConverterPinYin.getHanZiPY(str);
|
|
|
|
String code = PinyinUtil.getFirstLetter("王佳琪", ""); //c-s
|
|
|
|
StringBuffer buffer = new StringBuffer(code); |
|
|
|
code = buffer.replace(0, 1, firstString).toString(); |
|
|
|
code = code.toUpperCase(); |
|
|
|
System.out.println(code); |
|
|
|
} |
|
|
|
} |
|
|
|