How can I determine whether a char in a string is an ASCII, ISO 8859-1 or Unicode-only character?

J Rajendran

See Is ASCII considered a subset of Unicode, or are they disjoint sets? for the reason the code below works.

Assuming your target string is str1:

int len = str1.length(); 
int codePoint; 
char[] chars = str1.toCharArray(); 

for( int i=0; i < len; i++ ) 
{ 
  codePoint = (int) chars[i]; 
  if (codePoint < 128) 
  { 
    // This is an ascii char. 
  }
  else 
  if (codePoint < 256) 
  { 
    // This is an ISO 8859-1 char. 
  } 
  else 
  { 
    // This is a Unicode-only Char.
  } 
}
0 Comments  (click to add your comment)
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact