But the problem is, now i am trying to write a media center midlet which allow the user to view pictures. User can rename the file. What i concern here is if the phone for user A is support korean or chinese try to rename the file in chinese and save it in SD card. When it pass to user B with the phone not support korean or chinese, the file name cannot been display properly. What i want to do here is to limit the user only can rename the file with normal latin ascii code. Is there any way i can do like this way? Thanks for help!!
public boolean isASCII(String s){
char[] data = s.toCharArray();
for(int i=0;i<data.length;i++){
if( (data[i]&0x80) == 0x80){
return false;
}
}
return true;
}
This should do the trick I guess...>
i have a simply way to detect whether a text file is acsii or unicode.
just see the text file under binary way. u will see the difference in first several bytes.
gernally,if the text file is unicode form ,the start two bytes are:FF,FE.and if the text file is UTF8 form ,the start three bytes are:EF,BB,BF
but the acsii text hasn't extral information.
He just wants to know if java Strings contain unicode characters, so it is useless to look al text files!
The getBytes method won't work correctly. It will give you UTF8 data, and if it contains unicode, you will read failty data.It might work in most situations though.
The char method should also work just fine... I can't see why it shouldn't... maybee some casting probelems...
I am in Shanghai , China, so i use Chinese character to test the method. when i use "我"(i hope you can read chinese character) , the method will return true, though if i use "们". the reason might be as follows:
in unicode, the two bytes representing chinese character do not always start with 1. while in UTF8, they do.
so here, if i use UTF8, it ok.
Hmm, could you post the int values of any of these characters?
char unicodethingie = '...'; // put in some hebrew or arabic character
System.out.println("char: " +(int) unicodethingie;