|
@@ -1,5 +1,7 @@
|
|
|
package org.springblade.business.utils;
|
|
|
|
|
|
+import org.springblade.core.tool.utils.DateUtil;
|
|
|
+
|
|
|
public class StringSPUtils {
|
|
|
|
|
|
/***
|
|
@@ -51,14 +53,19 @@ public class StringSPUtils {
|
|
|
return alphatable[i];
|
|
|
}
|
|
|
|
|
|
- //根据一个包含汉字的字符串返回一个汉字拼音首字母的字符串
|
|
|
public String getStringSP(String SourceStr) {
|
|
|
StringBuilder Result = new StringBuilder();
|
|
|
int StrLength = SourceStr.length();
|
|
|
int i;
|
|
|
try {
|
|
|
for (i = 0; i < StrLength; i++) {
|
|
|
- Result.append(Char2Alpha(SourceStr.charAt(i)));
|
|
|
+ char ch = SourceStr.charAt(i);
|
|
|
+ // 判断是否是汉字
|
|
|
+ if (isChineseCharacter(ch)) {
|
|
|
+ Result.append(Char2Alpha(ch));
|
|
|
+ } else {
|
|
|
+ Result.append(ch);
|
|
|
+ }
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
Result = new StringBuilder();
|
|
@@ -66,6 +73,12 @@ public class StringSPUtils {
|
|
|
return Result.toString();
|
|
|
}
|
|
|
|
|
|
+ //判断字符是否是汉字
|
|
|
+ private boolean isChineseCharacter(char ch) {
|
|
|
+ //汉字的编码范围为'\u4e00'到'\u9fa5'
|
|
|
+ return (ch >= '\u4e00' && ch <= '\u9fa5');
|
|
|
+ }
|
|
|
+
|
|
|
private boolean match(int i, int gb) {
|
|
|
if (gb < table[i])
|
|
|
return false;
|
|
@@ -122,7 +135,7 @@ public class StringSPUtils {
|
|
|
|
|
|
/*public static void main(String[] args) {
|
|
|
StringSPUtils obj1 = new StringSPUtils();
|
|
|
- System.out.println(obj1.getStringSP("你好"));
|
|
|
+ System.out.println(obj1.getStringSP("你好NIHAO 00_1"));
|
|
|
System.out.println(obj1.getStringSP("欢迎你"));
|
|
|
String s = obj1.buildSerial(1, 4);
|
|
|
System.out.println(s);
|