-2
我想比较一个字符串与文件内容,并且想断言它们是否相等。两个相等的字符串不会传递断言
像:
13CB0000000000X15.xml (input)
13CB0000000000X15.xml (expected (content of file))
我断言:
assertTrue("Tatsaechliches Ergebnis weicht von '"
+ expectedResultFileName + "' ab!", result.equals(expected));
这种说法莫名其妙地失败,因为它说,它不等于?
我的文件是UTF-8不带BOM。没有LF/CRLF或其他。我甚至试图修剪它:
String expected = readFile(testDataBasePath +
File.separator + expectedResultFileName, encoding);
expected = expected.trim();
String result = document.getDocumentElement().getChildNodes().item(0).getNodeValue();
result = result.trim();
我错过了什么?
所以你从来没有检查过这些字符串中包含的字节和哪些字节丢失/过剩? – Tom
提示:当equals()告诉你你的字符串不相等时;那么他们没有。例如尝试比较它们的字符。 – GhostCat
谢谢@GhostCat,解决方法与你的方法。备案: 'char [] first = w1.toLowerCase()。toCharArray(); char [] second = w2.toLowerCase()。toCharArray(); int minLength = Math.min(first.length,second.length); for(int i = 0; i
0x45