/**
* 处理key,形如"XX(XX)",变为"XX"
* @param key
* @return
*/
public static String handleKey(String key) {
String str = "";
if (null != key && 0 != key.trim().length()) {
int i = 0;
//英文括号
if (-1 != key.indexOf("(")) {
i = key.indexOf("(");
str = key.substring(0, i);
//中文括号
} else if (-1 != key.indexOf("(")) {
i = key.indexOf("(");
str = key.substring(0, i);
} else {
str = key;
}
}
return str.trim().toString();
}
//测试数据
String str = "中国人(北京)";
String str1 = "中国龙 (上海)";
System.out.println("中文括号处理:" + handleKey(str));
System.out.println("英文括号处理:" + handleKey(str1));