-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