Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Unicode character Comparision Problem

Status
Not open for further replies.

pratham123

Programmer
Dec 16, 2003
12
IN
Hello friends
i got a problem for unicode character comparision problem.actually i want to check particular character is exist in the string or not.
here i m sendning a code just check and send me suggestion how to check it

set of unicode character.
static String chUnicode[] = { "\uE640", "\uE641","\uE63E",
"\uE642", "\uE643", "\uE644", "\uE645", "\uE646", "\uE647", "\uE648", "\uE64A", "\uE64B", "\uE64C", "\uE64D", "\uE64E", "\uE64F", "\uE651", "\uE652", "\uE653", "\uE654", "\uE655", "\uE656", "\uE657", "\uE658", "\uE659", "\uE65A", "\uE65B", "\uE65C", "\uE65D", "\uE65E", "\uE65F", "\uE660", "\uE661", "\uE662", "\uE663", "\uE664", "\uE665", "\uE666", "\uE667", "\uE668", "\uE669", "\uE66A", "\uE66B", "\uE66C", "\uE66D"};


public static boolean isImageCharacter(String strSource)throws UnsupportedEncodingException{
//String strSrc = new String(strSource.getBytes("UTF-8"),"UTF-8");
byte byteName[] = strSource.getBytes("UTF-8"); // ----Checking Each Character
String strByte1 = null;
String strByte2 = null;
// -------------
for (int nCountName = 0; nCountName < byteName.length; nCountName += 2) {
strByte1= byteToHex(byteName[nCountName]);
strByte2= byteToHex(byteName[nCountName+1]);
// -----Checking UNicode Array-----
for (int nCount = 0; nCount < chUnicode.length; nCount++){
byte byteReserve[] = chUnicode[nCount].getBytes("UTF-8");
String strImage1 =byteToHex(byteReserve[0]);
String strImage2 =byteToHex(byteReserve[1]);

if (strByte1.equals(strImage1) && strByte2.equals(strImage2)) {
return false;
}
}
}
return true;
}

public static String byteToHex(byte b) {
// Returns hex String representation of byte b
char hexDigit[] = {
'0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'a', 'b', 'c', 'd', 'e', 'f'
};
char[] array = { hexDigit[(b >> 4) & 0x0f], hexDigit[b & 0x0f] };
return new String(array);
}

public static String charToHex(char c) {
// Returns hex String representation of char c
byte hi = (byte) (c >>> 8);
byte lo = (byte) (c & 0xff);
return byteToHex(hi) + byteToHex(lo);
}







thnx in advance
regards
Alpesh
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top