How to check whether a character is from English language or not in Objective-C

Last day I needed to check the UITextField ‘s text whether it is from English language or other Unicode character form other language. And also how many characters are form English language and how many from others?

Here is how I solved this problem.

int counterEng=0;
int counterOther=0;
for(int i=0;i<[textField.Text length];i++)
unichar lastChar = [textField.Text characterAtIndex:i];
if(lastChar >= 0x000 && lastChar <=0x255)
NSLog(@"Other Language");

Here unichar is the type for Unicode characters and if its value is from 0x000 to 0x255 then this character is from English language. Otherwise it is from other language.

If you know any better solution please share with us.



About Razib Chandra Deb

I completed my BSc in CSE from CSE Department of KUET. Currently I am working as a Software Engineer in Samsung R&D Institute Bangladesh(SRBD). I am interested in image processing.
This entry was posted in CodeProject, iPhone and tagged , , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s