0

I want use only input japanese language but I don't know how to check between japanese input and anphabe input(sometime user could input a japanese character but missing something)
So what is my missing idea. I using a dictionary with two for loop but the performance so bad.

This is my code:

public List<String> getAnswer(String rawData) {
        int length = rawData.length();
        List<String> result = new ArrayList<String>();
        for (int i = 0; i < length; i++) {
            for (int j = 0; j < length - i; j++) {
                String subString = rawData.substring(i, i + j);
                if (mDict.containsKey(subString)) {
                    result.add(mDict.get(subString));
                        break;
                }
        }
    }
    return result;
}

And my dictionary:

<string-array name="dict_en">
   <item>a</item>
   <item>i</item>
   <item>u</item>
   <item>e</item>
   <item>o</item>
</string-array>
<string-array name="dict_ja">
   <item>あ</item>
   <item>い</item>
   <item>う</item>
   <item>え</item>
   <item>お</item>
</string-array>
Trần Đức Tâm
  • 4,037
  • 3
  • 30
  • 58
  • 1
    Two for loops? How? To query a dictionary? When you decide input is not Japanese? Is there a minimum number of characters? Did you consider to use UNICODE subrange checking for Hiragana/Katakana and CJK(s)? – Adriano Repetti Jun 04 '14 at 10:08
  • I have one loop which is `for(int i=0; i – Trần Đức Tâm Jun 04 '14 at 10:17
  • 1
    If you can enforce the usage of Japanese keyboard + disable copy\paste\select options ..then you wouldn't need to waste time checking – Khaled.K Jun 04 '14 at 10:19
  • Yeah! That's my opinion but I don't know how to `enforce the usage of Japanese keyboard` and `disable copy\paste\select options`. Please give me some prefer. – Trần Đức Tâm Jun 04 '14 at 10:29
  • Please click EDIT below your question and add the code you are using. In the question you say two for loops, and in comment only one for loop. Seeing the code will help others to help you. – Paul Jun 04 '14 at 10:31
  • I had edited my post. The first, i allow user input anphabe and i will change it to Hiragana character. The second i think that i will validate user's input. So now, I think you have a best way for me. However I don't know how to do what you say. I have never done it before. – Trần Đức Tâm Jun 04 '14 at 10:43

0 Answers0