要處理字符串
Medical Care ( Costs Inverse ## agonism ( Costs Inverse ## agonism ) ) Costs ( Inverse ## agonism ) at beta_1 ##adrenergic receptors
替換操作:將字符串中 所有括號 內的 ##替換成 @
處理結果:
Medical Care ( Costs Inverse @ agonism ( Costs Inverse @ agonism ) ) Costs ( Inverse @ agonism ) at beta_1 ## adrenergic receptors
各路高手幫幫忙 ( 正則表達式或者其它方法都行的 )
public static void main(String[] args) {
String s = "Medical Care ( Costs Inverse ## agonism ( Costs Inverse ## agonism ) ) Costs ( Inverse ## agonism ) at beta_1 ##adrenergic receptors";
String returnValue = "";
String [] str = s.split("\\)");
for (int i = 0; i < str.length; i++) {
if(" ".equals(str[i])){
str[i] = ")";
}
if(str[i].contains("(")){
str[i] = str[i].replaceAll("##", "@@")+")";
}
}
s = ArrayUtils.toString(str).replace(",", " ");
returnValue = s.substring(1, s.length()-1);
System.out.println(returnValue);
}