[Encode] java replaceall 특수문자
1. []으로 싸주면 문자자체로 인식하는 것들.
* ⇒ [*]
+ ⇒ [+]
$ ⇒ [$]
| ⇒ [|]
2. \\를 붙여줘야 하는 것들.
( ⇒ \\(
) ⇒ \\)
{ ⇒ \\{
} ⇒ \\}
^ ⇒ \\^
[ ⇒ \\[
] ⇒ \\]
3. 자바의 특수문자는 \을 쓴다.
" ⇒ \"
4. 나머지 부호들은 괜찮은 듯 하다.
확인된 것.
! # % & @ ` : ; - . < > , ~ '
ex ) 위에 놈들 다 지워 보자.
String c = "!\"#$%&(){}@`*:+;-.<>,^~|'[]";
c = c.replaceAll("!\"#[$]%&\\(\\)\\{\\}@`[*]:[+];-.<>,\\^~|'\\[\\]", "");
public static String getSTRFilter(String str){
int str_length = str.length();
String strlistchar = "";
String str_imsi = "";
String []filter_word = {"","\\.","\\?","\\/">\\~","\\!","\\@","\\#","\\$","\\%","\\^","\\&","\\*","\\(","\\)","\\_","\\+","\\=","\\|","\\\\","\\}","\\]","\\{","\\[","\\\"","\\'","\\:","\\;","\\<","\\,","\\>","\\.","\\?","\\/"};
for(int i=0;i<filter_word.length;i++){
//while(str.indexOf(filter_word[i]) >= 0){
str_imsi = str.replaceAll(filter_word[i],"");
str = str_imsi;
//}
}
return str;
}
import java.util.StringTokenizer;
public class WebUtil
{
// 문자열 변환 String a= "abc" => replace(a, "c") => a : ab
public String strReplace(String s1, String s2){
String res = "";
StringTokenizer str = new StringTokenizer(s1, s2);
while(str.hasMoreTokens()){
res += str.nextToken();
System.out.println(res);
}
return res;
}
}
출처 : http://lazli.tistory.com/47