0

Question changed.

i wanna find that an character in a String is Persian or English char.

after search in codes, i find that this code in PHP: var ucs2 = text.search(/[^\x00-\x7D]/) =-1 can search in an string & when find a character that was not equal to value of ucs2 , return -1 ;

now what is equal to this command code in java & android? how i can search a character in a string without a for Loop & a array of character?

Saeid
  • 2,261
  • 4
  • 27
  • 59
  • You may want to put more log after matn and num and see what are the values before sending the sms. – Saeid Farivar Nov 03 '13 at 18:31
  • salam - saeid jan motavajeh nashodam daghighan! – Saeid Nov 03 '13 at 18:55
  • in onClick method after String matn = .... and String num = ...., put Log.d("Tag","matn = " + matn + " num = " + num)! (bebin che meghdari dari mikhooni az user input. bebin hamoon ke mikhay hast ya na...) – Saeid Farivar Nov 03 '13 at 19:18
  • na saeid jan - ye toast gozashtam to try ke meghdar input number karbar ro barmigardone . unja doroste vali to samaneye payam kotah hamishe ye shomare ro daryaft mikone! – Saeid Nov 04 '13 at 08:21
  • bebin, to aks ke maloome ke matne ke vared mikone har seri to samaneye payam kotah dorost daryaft mikoni. moshkel shomarast ke hamishe ye chize? ke fekr konam dalilesh ene ke az ye device hamishe estefade mikone bara test... agar beri az ye device dige befresti shomarash avaz mishe ... ya ye sim card e dige estefade koni... – Saeid Farivar Nov 04 '13 at 22:42
  • moshkel raf shod --------- ba hamon adevice ghabli ye jayi khondam avale shomare ye "+" bezaram mesle in {.sendTextMessage("+98500029224301",} ------------- ye moshkel ham to tahlile ghesmat server bod kr raf shod ---------- alan bedone {+98} ham javab mide ------ be harhal , bazam mamnon ------- rasti inja nemishe add friends kard? – Saeid Nov 05 '13 at 08:04
  • @saeid which programming language do you use? I have no idea about php. tag your question to the relevant ones like php java android... – Raghunandan Nov 27 '13 at 10:37
  • i use eclipse.ADT - i wanna use this php code in java(android). – Saeid Nov 27 '13 at 10:51

1 Answers1

1

this may help you...

It searches for a character in String based on it's ASCII code. thus you can use in many languages...

private static int searchCharacter(String string, char ch) {
    final int chASCII = (int) ch;
    return seachCharacter(string, chASCII);
}

private static int seachCharacter(String string, int chASCII) {
    if (string == null || string.isEmpty()) {
        return -1;
    }
    for (int i = 0; i < string.length(); i++) {
        char c = string.charAt(i);
        int cASCII = (int) c;
        if (chASCII == cASCII) {
            return i; // found at index i
        }
    }
    return -1;
}
Gopal Gopi
  • 11,101
  • 1
  • 30
  • 43
  • Thanks - just this Section was Helpful for me : int cASCII = (int) c; - I already used this;But I did not know how wotk ; & know find; – Saeid Nov 28 '13 at 09:48
  • an another question; how i can fine Cursor Position in a text view؟ – Saeid Nov 28 '13 at 09:50
  • 1
    to find cursor position in EditText, see here http://stackoverflow.com/questions/6900408/get-cursor-position-in-android-in-edit-text – Gopal Gopi Nov 28 '13 at 09:58
  • right - but in typing ; if you want change a char or e.g , should touch a position , after u touch a position , shown a cursor that is your actual position for type - i need that position - is this possible? – Saeid Nov 28 '13 at 10:05
  • i know but this was very helpful!:D – Saeid Nov 28 '13 at 10:38
  • ASCII code of zero is 48 and ASCII code of 'a' is 97. so if any character whose ASCII code is in between 48 and 97, then that is in between 0 and a – Gopal Gopi Nov 28 '13 at 12:14
  • Sorry my mean was this : Between ^@ to z ; this link : http://defindit.com/ascii.html ...... In Fact i wanna that in a Edit-text,when user enter a Persian char,app return a -1 Value ....... i find that,my Persian char(s) there aren't in this Intervals (From x00 to x7D) - That's it. – Saeid Nov 28 '13 at 12:26
  • determine your persian characters ASCII range using OS's which supports Persian language. for example, you can write text in many languages in LINUX CENT OS like telugu (Indian language). – Gopal Gopi Nov 28 '13 at 12:40
  • I'm Persian Myself - But i wanna my android app detect Persian Char; – Saeid Nov 28 '13 at 12:47
  • see this http://en.wikipedia.org/wiki/List_of_Unicode_characters and do some research – Gopal Gopi Nov 28 '13 at 12:57