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); |
|