How do I detect unicode characters in a Java string?

前端 未结 6 1787
不思量自难忘°
不思量自难忘° 2020-12-03 10:28

Suppose I have a string that contains Ü. How would I find all those unicode characters? Should I test for their code? How would I do that?

For example, given the str

6条回答
  •  感动是毒
    2020-12-03 10:57

    You could go the other way round and ask if the character is an ascii character.

    public static boolean isAscii(char ch) {
        return ch < 128;
    }
    

    You'd have to analyse the string char by char then of course.

    (the method is from commons-lang CharUtils which contains loads of useful Character methods)

提交回复
热议问题