Why is a different to b?
String a = "BuildGUID10035\0528\0440";
String b = "BuildGUID10035" + '\0' + 528 + '\0' + 440;
System.out.println("A: " + a);
System.out.println("B: " + b);
System.out.println(a.equals(b));
They are different because in the first string, \052 gets interpreted as a single octal escape sequence (and so is \044).
The following two strings do compare equal:
String a = "BuildGUID10035\000528\000440";
String b = "BuildGUID10035" + '\0' + 528 + '\0' + 440;
(I've replaced the \0 with \000 in a.)
\052 and \044 are octal representations of characters. Anything starting with \ and three digits are considered as octal forms of characters. Hence, two strings are not equal.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With