Java - removing strange characters from a String

前端 未结 11 668
轮回少年
轮回少年 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:08

    Justin Thomas's was close, but this is probably closer to what you're looking for:

    String nonStrange = strangeString.replaceAll("\\p{Cntrl}", ""); 
    

    The selector \p{Cntrl} selects "A control character: [\x00-\x1F\x7F]."

提交回复
热议问题