// 初始化
static {
for (int i = 0; i < 26; i++) {
table = gbValue(chartable);// 得到GB2312码的首字母区间端点表,十进制。
}
table[26] = END;// 区间表结尾
}
public static String Dms(String pk){
Date date=new Date();
pk=(new SimpleDateFormat("yyyyMMddhhmmssSSS")).format(date);
return pk;
}
// ------------------------public方法区------------------------
// 根据一个包含汉字的字符串返回一个汉字拼音首字母的字符串 最重要的一个方法,思路如下:一个个字符读入、判断、输出
public static String Cpy(String SourceStr) {
String Result = "";
int StrLength = SourceStr.length();
int i;
try {
for (i = 0; i < StrLength; i++) {
Result += Caz(SourceStr.charAt(i));
}
} catch (Exception e) {
Result = "";
e.printStackTrace();
}
return Result + Dms("now");
}
// ------------------------private方法区------------------------
/**
* 输入字符,得到他的声母,英文字母返回对应的大写字母,其他非简体汉字返回 '0' *
*/
private static char Caz(char ch) {
// 对英文字母的处理:小写字母转换为大写,大写的直接返回
if (ch >= 'a' && ch <= 'z') {
return (char) (ch - 'a' + 'A');
}
if (ch >= 'A' && ch <= 'Z') {
return ch;
}
// 对非英文字母的处理:转化为首字母,然后判断是否在码表范围内,
// 若不是,则直接返回。
// 若是,则在码表内的进行判断。
int gb = gbValue(ch);// 汉字转换首字母
if ((gb < BEGIN) || (gb > END))// 在码表区间之前,直接返回
{
return ch;
}
int i;
for (i = 0; i < 26; i++) {// 判断匹配码表区间,匹配到就break,判断区间形如“[,)”
if ((gb >= table) && (gb < table[i + 1])) {
break;
}
}
if (gb == END) {// 补上GB2312区间最右端
i = 25;
}
return initialtable; // 在码表区间中,返回首字母
}