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:
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
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>