文件名称:特殊字符前面加斜线的代码
文件大小:407B
文件格式:TXT
更新时间:2013-11-28 09:58:31
特殊字符前面加斜线的代码
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);