Handling unicode encoded barcodes in Java
2-D barcode formats such as PDF-417 can encode a huge character set, which means that the barcode reader toolkit needs to encode characters outside the normal ASCII range. If the Encoding property is set to 2 then the toolkit will use Unicode encoding, whereby characters can be represented by the string &#N; where N is an integer.
For example:
Ñ represents the character Ñ
The following Java function may be used to decode such a string:
String decodeBarcodeString(String barcodeString) throws Exception{
String decodedString = “”;
String tempString = “”;
char []array = barcodeString.toCharArray();
for(int i=0; i<array.length;i++){
if(array[i]==’&’)i++;
if(array[i]==’#’){
int j = i;
int count = 0;
int value = 0;
tempString=””;
while(array[++j]!=’;’){
count++;
tempString+=array[j];
}
i+=(count+1);
value = Integer.parseInt(tempString);
if(value==0){
decodedString+=” “;
}else {
decodedString+=Character.toString((char)value);
}
}else{
decodedString+=array[i];
}
}
return decodedString;
}
The above function was kindly supplied by TigerIT Bangladesh Ltd www.tigeritbd.com