I've got an odd little problem: two strings which appear to the naked eye to be identical are showing up as different when I use java.lang.String.compareTo(String). The relevant code is: ... byte good[] = welcome.getData(); String goodStr = new String(good); String want = new String("GDNP OK\n\n"); System.out.println(want); int wasGood = goodStr.compareTo(want); System.out.println(wasGood); if (wasGood == 0) { didOK = true; System.out.println("Got welcome string"); } else { System.out.println("Handshake failed: packet was " + goodStr); } My output reads thusly: GDNP OK
1 Handshake failed: packet was GDNP OK
Couldn't connect; dying This doesn't make any sense to me at all. Just in case it's relevant, welcome -- where my first String is coming from -- is a DatagramPacket. Any ideas why this wouldn't work? Alex Kirk
Rene Marot
Greenhorn
Joined: Jun 27, 2001
Posts: 9
posted
0
Hello, I don't knwon if it comes from the function you use to compare string but you can try to display each byte of your good[] array so you can see what they realy are. You may have an unvisible charater like asc(000) witch is different of a space but sometime looks like on screen. Bye.