java - Code for searching in a String if it contains a Char[] array? -


I am developing an app to find a text ( searchString ) in Arabic There is a feature language if it is in .txt file (.txt file is also in Arabic language).

Since Android Arabic does not support 100%, String.indexof () does not work properly, I thought, I have searchString in a four [] array and instead of comparing the whole word, I compare each character. So I put searchString in a char [] and started comparing the array in the string

Is it available code available anywhere Finds that the sequence is in this four [array] string?

Example:

  char [] = {T, E, S, T} string 1 {qqwtestq} string 2 {qwqtqwe} - & gt; String 1: True String 2: Fells   

Thanks

< Do not use any type of character encoding in the code> IndexOf and in and you can use characters that have not been used for example in your character encoding. That is, these tasks are ignored.

All String.indexOf () and include the character for the character, I'm not sure what you are hoping for 100% Arabic support. Here is a simplified version that is included in indexOf ()

  public static integer (string string, four [] characters) {LOOP: for (int i = 0; i & Lt; String.length () - chars.length; i ++) {for (int j = 0; j & lt; chars.length; j ++) if (string.charAt (i + j)! = Character [J]) loop release; Return i; } Return -1; } Public static zero principal (string algos []) {four [] character = "exam" Kocharaire (); String a = "qqwtestq"; String two = "qwqtqwe"; String str = new string (character); System.out.println ("indexoff (" + one + "," + array.Tosting (character) + ") =" + indexoff (one, characters)); System.out.println (one + ".indexOf (" + str + ") =" + one.indexOf (str)); System.out.println ("indexoff (" + 2 + "," + Arrays.toString (character) + ") =" + Indexoff (two, characters)); System.out.println (two + ".indexOf (" + str + ") =" + two.indexOf (str)); Four [] character 2 = {'\ uffff', '\ uFeFF'}; String test = "qqw \ uffff \ uFeFFq"; String str2 = new string (character 2); System.out.println ("indexOf (" + test + "," + arrays.toString (chars2) + ") =" + Indexoff (test, character 2)); System.out.println (test + ".indexOf (" + str2 + ") =" + test.indexOf (str2)); }   

print

  indexOf (qqwtestq, [t, e, s, t]) = 3 qqwtestq.indexOf (test) = 3 indexOf (qwqtqwe ), [T, E, S, T]) = -1 qwqtqwe.indexOf (test) = -1 index (qqw ?? q, [?,?]) = 3 qqw ?? Q.indexOf (??) = 3   

Can you provide an example where this method does not work?

Edit: This test examines every possible character to see if the index behaves as expected, that is, for every possible character. (Int i = character. MIN_VALUE; i & lt; = Character.MAX_VALUE; i ++) {Find String = New String (New Letter [] {(char) i} ); String str = new string (new four [] (four) (i + 1), (four) i}); string str1 = new string (new four [] ((four) (i + 1)}); int Test1 = str.indexOf (find); if (test1! = 1) put new cover error ("test1 fail i =" + i); int test2 = str1.indexOf (find); if (test2! = -1) new Antitrust error ("test2 fail i =" + i) throwing;}

No inconsistency.

Comments