Piyush
Piyush

Reputation: 53

How to check that entered string contains Unicode: 0x1a value

I want to know that entered string is contains Unicode:0x1a value or not in java. I am not able to identify the value of → and other special character.

Upvotes: 3

Views: 2747

Answers (1)

vz0
vz0

Reputation: 32923

Because the character "→" has a Unicode code point \u2192.

String s = "this is → my arrow";
if (s.contains("→")) {
  System.out.println("Contains arrow!");
} else {
  System.out.println("No arrows in my string :(");
}

As an alternative you may write the character in hex notation:

String s = "this is → my arrow";
if (s.contains("\u2192")) {
  System.out.println("Contains arrow!");
} else {
  System.out.println("No arrows in my string :(");
}

Upvotes: 6

Related Questions