• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem Converting to Decimal NCR in Linux using java code

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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



public class DecimalToHexadecimal{

public static void main(String[] args){
System.out.println(convertToDecimalNCR1(args[0]));
}

private static String convertToDecimalNCR1(String str) {
System.out.println(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;
}

}

 
Ranch Hand
Posts: 1923
Scala Postgres Database Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Maybe I'm allowed to put some indentation to your code, as well as code-blocks?

I don't see anything here, which should lead to OS-specific behaviour. Can you please give us some testcases:

Input, output, intendet output/output on windows.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic