char[] specialChars = {'(',')','*','.'};
String test = "()*.";
String result = "";
char temp;
boolean isExist = false;
for (int i = 0; i < test.length(); i++) {
temp = test.charAt(i);
isExist = false;
for (int j = 0; j < specialChars.length; j++) {
if (temp == specialChars[j]) {
isExist = true;
break;
}
}
result += ((isExist ? "\\" : "")+temp);
}
System.out.println(result);
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请
点击举报。