달력

4

« 2024/4 »

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
2012. 7. 24. 09:34

[Java] replaceAll 로 공백 제거하기 Enjoy/JAVA2012. 7. 24. 09:34

출처 : http://vicki.tistory.com/583


정규식에서 공백은 정확하게 공백으로 인식을 못하는 것 같았습니다.
Pattern JavaDoc 에서 내용을 확인하였습니다.
http://java.sun.com/javase/6/docs/api/java/util/regex/Pattern.html

POSIX character classes (US-ASCII only)
\p{Lower}A lower-case alphabetic character: [a-z]
\p{Upper}An upper-case alphabetic character:[A-Z]
\p{ASCII}All ASCII:[\x00-\x7F]
\p{Alpha}An alphabetic character:[\p{Lower}\p{Upper}]
\p{Digit}A decimal digit: [0-9]
\p{Alnum}An alphanumeric character:[\p{Alpha}\p{Digit}]
\p{Punct}Punctuation: One of !"#$%&'()*+,-./:;<=>?@[\]^_`{|}~
\p{Graph}A visible character: [\p{Alnum}\p{Punct}]
\p{Print}A printable character: [\p{Graph}\x20]
\p{Blank}A space or a tab: [ \t]
\p{Cntrl}A control character: [\x00-\x1F\x7F]
\p{XDigit}A hexadecimal digit: [0-9a-fA-F]
\p{Space}A whitespace character: [ \t\n\x0B\f\r]


그래서 아래와 같이 수정하였습니다.
  1. String str = "Vicki Yi";   
  2.   
  3. System.out.println(str + " : " + str.replaceAll("\\p{Space}"""));  
1.String str = "Vicki Yi";
2. 
3.System.out.println(str + " : " + str.replaceAll("\\p{Space}"""));


결과는~~~ 원하는 결과가 나왔습니다.
Vicki Yi : VickiYi

:
Posted by 라면스프