I want to compare two strings using Java. First sting name i get from .mif file using GDAL in cp1251 encoding. Second kadname i get from jsp. To compare i do this:
if (attrValue instanceof String)
{
String string3 =
new String((attrValue.toString()).getBytes("ISO-8859-1"), "cp1251");
dbFeature.setAttribute(name, string3);
System.out.println("Name=" + name);
System.out.println("kadname=" + kadname);
if (name.equalsIgnoreCase(kadname))
{
kadnum = string3;
System.out.println("string3" + string3);
}
}
And in console i get this:
Name = kadnumm
kadname = kadnumm
Whats wrong with this?
The only reason I can see for them not being equal is the leading or trailing whitespace.
You can
trimthe string to remove any of those whitespaces, and then compare them: –Or, there might be some other
non-printablecharacters, which won’t get removed bytrimming. You can try printing your strings insingle quotes, and check whether there are any: –