Skip to main content

Problem Converting to Decimal NCR in Linux using java code

No replies
avinash_reddy
Offline
Joined: 2010-08-12
Points: 0

Hi,

I am trying to convert a given string to its corresponding Decimal NCR using the following code. This code seems to work fine in windows but when I use the same code in linux environment it started giving wrong output. Can some help me with this???

Thanks

private static String convertToDecimalNCR1(String str) {
String preserve="ascii";
String before="&#";
String after=";";
int haut = 0;

String cp;
String CPstring = "";
for (int i = 0; i < str.length(); i++) {
int b = str.codePointAt(i);
if (b < 0 || b > 0xFFFF) {
return null;
}
if (haut != 0) {
if (0xDC00 <= b && b <= 0xDFFF) {
cp = ""+0x10000 + ((haut - 0xD800) << 10) + (b - 0xDC00);
CPstring += before + cp + after;
haut = 0;
continue;
}else {
return null;
}
}
if (0xD800 <= b && b <= 0xDBFF) {
haut = b;
}else {
if (preserve.equals("ascii")&& b <= 127) {
CPstring += str.charAt(i);
}else {
cp = ""+b;
CPstring += before + cp + after;
}
}
}
return CPstring;
}

Message was edited by: avinash_reddy

<= b && b <= 0xDFFF) {
cp = ""+0x10000 + ((haut - 0xD800) << 10) + (b - 0xDC00);
CPstring += before + cp + after;
haut = 0;
continue;
}else {
return null;
}
}
if (0xD800 <= b && b <= 0xDBFF) {
haut = b;
}else {
if (preserve.equals("ascii")&& b <= 127) {
CPstring += str.charAt(i);
}else {
cp = ""+b;
CPstring += before + cp + after;
}
}
}
return CPstring;
}

Message was edited by: avinash_reddy