特殊字符前面加斜线的代码

时间:2013-11-28 09:58:31
【文件属性】:
文件名称:特殊字符前面加斜线的代码
文件大小: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);

网友评论

  • 晕,白下载了,就是简介那几行java代码