修正中文拼音首字母空数组判断

字符串不是中文字符,会返回空数组,需要判断
This commit is contained in:
zhouinfo
2022-02-15 06:53:57 +00:00
committed by Gitee
parent 233a00ad89
commit 2e26ccf33b

View File

@@ -52,7 +52,7 @@ public class PinyinUtils {
if (arr[i] > 128) {
try {
String[] temp = PinyinHelper.toHanyuPinyinStringArray(arr[i], Static.defaultFormat);
if (temp != null) {
if (temp != null && temp.length > 0) {
pybf.append(temp[0].charAt(0));
}else{
pybf.append(String.valueOf(arr[i]));
@@ -155,7 +155,7 @@ public class PinyinUtils {
}
// public static void main(String[] args) {
// String str = "你好123世界abc,~!#$_Sdf-";
// String str = "你好123🅻🅾🆅🅴、世界abc,~!#$_Sdf-";
// System.out.println(getFirstSpell(str));
// System.out.println(getFirstSpell(str, false));
// System.out.println(getFullSpell(str));