SSISO Community

시소당

자바에서 정규표현식으로 특정유니코드 제거 예제

문자열에  포함된  유니코드  \u0001~\u0020    까지를  공백으로  치환하기

---------------------------------------------------------

  

import  java.io.*;
public  class  Unicode{
  public  static  void  main(String  []  args)  throws  Exception{
  
    FileWriter  fw  =  new  FileWriter("unicode.txt",false);

    int  uni  =  0x01;
    for(int  i=0;  i<100;  i++)  {
      //System.out.println(  (char)uni  +  "  :  "  +  uni);
      fw.write(  (char)uni  +"\n");
      uni++;
    }

    fw.close();

    BufferedReader  br  =  new  BufferedReader(  new  FileReader("unicode.txt")  );
    String  str  =  null;
    StringBuffer  sb  =  new  StringBuffer();
    while(  (str=br.readLine())!=null  )  {
      //System.out.println(  str  );
      sb.append(str);
    }
    br.close();

    String  strR  =  sb.toString();  
    System.out.println(  strR  );
    System.out.println(  strR.replaceAll("[\\u0001-\\u0020]","")  );
    
  }
}

[출처]  자바에서  정규표현식으로  특정유니코드  제거  예제|작성자  강장군
http://blog.naver.com/kkcgen?Redirect=Log&logNo=40022525666

1947 view

4.0 stars