Java: help comparing unusual character windows/linux

lozina

Lifer
Sep 10, 2001
11,711
8
81
we make a call to a web service which returns XML data. In this data there is sometimes a special character (¤) which we need to be able to look for. In windows I can just say something like indexOf("¤") and it works fine. But this does not work in linux.

any idea how I would go about matching this character reliably in both windows and linux?
 

lozina

Lifer
Sep 10, 2001
11,711
8
81
it makes no diff. the special character is there no matter what we parse it with. its part of the data
 

HigherGround

Golden Member
Jan 9, 2000
1,827
0
0
what's the unicode seq for that character? can you find it in a stream when you tcpdump eth on a client side?
 

lozina

Lifer
Sep 10, 2001
11,711
8
81
it's unicode is \u2021 and if I search for that in Windows it works but in linux it does not. Even though it is a single character in linux if I output it to logs it is printed out as 3 bizarre characters together.

edit: sorry for the confusion- I'm referring now to this char: ?, not the same as the one I was dealing with the other day. There are a couple more chars like that. in linux they turn into other characters. like the ? becomes equivalent to a ¥
 

lozina

Lifer
Sep 10, 2001
11,711
8
81
I don't really understand why it worked, but what I did was I got the byte value of the character and then I just made a string like this:

String crossChar = new String(new byte[] { (byte)-121 });

that for example, is for the ? character

Now when I compare a string looking for that string it finds it both in linux and windows.

This did not work in linux: str.indexOf("?");
but this does: str.indexOf(crossChar);
and still works in windows too.

no idea why it works and why the old way didnt.

 

Nothinman

Elite Member
Sep 14, 2001
30,672
0
0
It's possible it's some interaction with your locale setting on Linux that's throwing it off.
 

nweaver

Diamond Member
Jan 21, 2001
6,813
1
0
Originally posted by: Nothinman
It's possible it's some interaction with your locale setting on Linux that's throwing it off.

that was my first thought