0

I want to manually check each character of a string for whether it contains any full width characters. Can someone help me?

This is what I have so far:

public boolean areAnyFullWidth(String input) {
    for (char c : input.toCharArray())
        if ((c & 0xff00) == 0xff00)
            return true;
        return false;
}
TylerH
  • 20,799
  • 66
  • 75
  • 101
healer
  • 93
  • 2
  • 12
  • what does full width means ? – xsami Jun 13 '17 at 01:34
  • full width characters are letters or numbers like this asd123-45 – healer Jun 13 '17 at 01:36
  • I just follow the instruction in this link sir [link](https://stackoverflow.com/questions/29508932/how-check-if-string-has-full-width-character-in-java) – healer Jun 13 '17 at 01:37
  • @ErwinBolwidt When i say letters or numbers like this I mean characters that taking a much wider space in computer compare to a normal one – healer Jun 13 '17 at 01:39
  • I just found that link: https://stackoverflow.com/questions/29508932/how-check-if-string-has-full-width-character-in-java - so, it completely describes how to check for "full width" characters. What specific question do you have that is *not* answered by that post? – Erwin Bolwidt Jun 13 '17 at 01:41
  • I want to restrict an input string with full width characters regarding of what character is it. His code accept full width characters like chinese and japanese letters – healer Jun 13 '17 at 01:44
  • @healer Ok, if that's what your issue is, **edit** (see link under) the question and put it in there. – Erwin Bolwidt Jun 13 '17 at 02:56

1 Answers1

1

If you know the start and end unicode full width range then things are very simple.

Say the range is 0xFFOO to 0xFFEF:

public boolean areAnyFullWidth(String input) {
    for(char c : input.toCharArray())
        if(c >= 0xFFOO && c <= 0xFFEF)
            return true;
        return false;
}
Mordechai
  • 15,437
  • 2
  • 41
  • 82