0

I have a string that contains: ½

From my understand i belive this is \uFFFD

Can someone help me with why this syntax does not work:

if (promotions.getText().contains("\uFFFD")) {
                return promotions;
}
userMod2
  • 8,312
  • 13
  • 63
  • 115
  • Possible duplicate of [How do I detect unicode characters in a Java string?](http://stackoverflow.com/questions/1673544/how-do-i-detect-unicode-characters-in-a-java-string) – Yassin Hajaj Oct 15 '15 at 16:51
  • why not use `if (promotions.getText().contains("½")) { return promotions; }`? – javaguest Oct 15 '15 at 16:53

2 Answers2

2

½ is \u00BD

Therefore this should work

if (promotions.getText().contains("\u00BD")) {
wero
  • 32,544
  • 3
  • 59
  • 84
0

Try this:

if (promotions.getText().contains("\u00BD"))
{ 
    return promotions;
}
liquidsystem
  • 634
  • 5
  • 15
  • While this may theoretically answer the question, it's not really a good answer, since it doesn't teach the OP. Instead it gives an alternative solution without explanation. This will usually lead to OP not learning, and coming back for asking a new question when a similar problem occurs. Would you mind adding some explanation? – Vogel612 Oct 16 '15 at 10:36