I need to check if a character is an apostrophe. This is my code so far:
public boolean isWordCharacter(int c) {
if ((char) c == '\'')
return true;
else return Character.isLetter(c);
}
However, it never actually gets into the if ((char) c == '\'')
part. Is there something wrong with the way I check it? Thanks!
We have a global variable myString which holds a string as its value. In the event handler function, we are using the includes() method and ternary operator ( ? ) to verify whether myString contains apostrophe or not. Depending upon the result of the check, we will assign “Yes” or “No” to the result variable.
An apostrophe is commonly used to indicate omitted characters, normally letters: It is used in contractions, such as can't from cannot, it's from it is or it has, and I'll from I will or I shall.
Encoding. The letter apostrophe is encoded at U+02BC ʼ MODIFIER LETTER APOSTROPHE. In Unicode code charts it looks identical to the U+2019 ' RIGHT SINGLE QUOTATION MARK, but this is not true for all fonts.
You could simply use if(c=='\'')
without cast. Or you can use ascii value of apostrophe which is 39. if (c==39)
will do.
it never actually gets into the 'if ((char) c == '\'') part
The only reason for this could you never pass apostrophe to isWordCharacter(). You can verify it by manually sending 39
or '\''
to that function.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With