0

I like to implement custom search in cyrillic in my android application. However, I notice that ascii value from keyboard and ascii value for the same characters read from resource file are different, so there is no way to implement custom search. Could somebody help me?

Here is my code, in which I realise that ascii values are different:

  1. From keyboard (Macedonian keyboard) where s is charsequence from edit text control:

            byte[] bytes=null;
            try {
                bytes = s.toString().getBytes("UTF-8");
    
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
    
            String str=new String(bytes);
    
            byte [] arrayFromInput=toAsciiArray(str);
    

I got this for 'o' - ASCII 111

  1. from resource file

          String strRes=getResources().getString(R.string.o1).toLowerCase();
            byte [] bytes1=null;
            try {
               bytes1 =strRes.getBytes("UTF-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
            String str1=new String(bytes1);
            byte [] arrayFromData=toAsciiArray(str1);
    

I got this for 'o' ASCII 62

Here is my toAssciiArray function:

public static byte[] toAsciiArray(CharSequence charSequence) {
    if (charSequence == null) {
        return null;
    }
    byte[] barr = new byte[charSequence.length()];
    for (int i = 0; i < barr.length; i++) {
        barr[i] = (byte) toAscii(charSequence.charAt(i));
    }
    return barr;
}

public static int toAscii(char c) {
    return c;

}

Here is my resource file:

   <?xml version="1.0" encoding="utf-8"?>
   <resources>
      <string name="o1">о</string>
   </resources>
Selvin
  • 6,598
  • 3
  • 37
  • 43
vikifor
  • 3,426
  • 4
  • 45
  • 75
  • 'got this for 'o' ASCII 62'. Where? And is that a cyrillic char? Please show more complete code including the used EditText. In short: show reproducable code. Also show the search code and data. – greenapps Sep 29 '15 at 14:52
  • Yes ASCII 62 is for 'o', and 'o' is cyrillic char read from string resource file – vikifor Sep 29 '15 at 14:59
  • Bad choice as it is like latin o. Why not choose something like ж or ы? And please react on all my comments by answering all questions an supplying missing code. – greenapps Sep 29 '15 at 16:04
  • First I asked question about search in listview for cyrillic. Here is it http://stackoverflow.com/questions/32842561/search-cyrillics-in-custom-listview-does-not-work-android. Then one user gives me suggestion to get ascii values from the characters and I try this and realise that they are different , i can' t understand why. That' s why I asked another question – vikifor Sep 29 '15 at 16:29
  • I tried for example with с and ascii codes were the same. I can' t get why are different for o. How can I handle this – vikifor Sep 29 '15 at 16:31
  • You do not have to explain why you have another question. You should instead react to the point to comments. – greenapps Sep 29 '15 at 16:31

0 Answers0