Java - removing strange characters from a String

前端 未结 11 680
轮回少年
轮回少年 2020-12-10 03:04

How do I remove strange and unwanted Unicode characters (such as a black diamond with question mark) from a String?

Updated:

Please tell me the Unicode chara

11条回答
  •  爱一瞬间的悲伤
    2020-12-10 03:05

    Put the characters that you want to get rid of in an array list, then iterate through the array with a replaceAll method:

    String str = "Some text with unicode !@#$";
    ArrayList badChar = new ArrayList();
    badChar= ['@', '~','!']; //modify this to contain the unicodes
    
    for (String s : badChar) {
       String resultStr = str.replaceAll(s, str);
    }
    

    you will end up with a cleaned string "resultStr" haven't tested this but along the lines.

提交回复
热议问题