!23 修正中文拼音首字母空数组判断字符串不是中文字符,会返回空数组,需要判断

This commit is contained in:
thinkgem
2022-02-15 15:18:21 +08:00
parent 57e172802d
commit 3719e62fb6

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,6 +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));