0

i have two values:

String a = "00tz"; // (Eclipse internal debug value: [, 0, 0, t, z]) and 
String b = "tz"; //   (Eclipse internal debug value: [, t, z])

I am reading this values from an ArrayList like

for (String a : stringLists) {
...
}

I get "false" when i compare this two values with StringUtils.containsIgnoreCase(a,b). But it should return true because "tz" is existing in "00tz".

Im using apache.commons.lang3.StringUtils. To change the values a & b didn't worked. The length of "a" is 5 and "b" is 3. It also returns false when i use a.contains(b).

These are the results when i output the value with

System.out.println(Arrays.toString(a.getBytes(StandardCharsets.UTF_8)));

a:[-17, -69, -65, 48, 48, 118, 119]
b:[-17, -69, -65, 118, 119]

Im reading this values from a .txt file which contains several values like this. I read it in this way:

File fileA = new File("test/a.txt"); 

File fileB = new File("test/b.txt"); 

lista = (ArrayList<String>) FileUtils.readLines(fileA, "utf-8");

listb = (ArrayList<String>) FileUtils.readLines(fileB, "utf-8");

Do you have an idea what the problem is?

Thank you!

  • If you check the `.length` property of both, is the same as the amount of characters you can see? – npinti Jun 21 '16 at 13:25
  • 1
    Is `[, t, z]` supposed to be `[t, z]` or is it something like `[\0, t, z]` ? – khelwood Jun 21 '16 at 13:26
  • 2
    I will give you a hint: Try `StringUtils.containsIgnoreCase(b, a)`. – Xaver Kapeller Jun 21 '16 at 13:26
  • 2
    Can you provide a [Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve) ? – Florent Bayle Jun 21 '16 at 13:27
  • You should mention which libraries you use. StringUtils could be apache or Spring or ... – niekname Jun 21 '16 at 13:30
  • Hi im using "apache.commons.lang3" library. To change the values a&b didnt work. The length of "a" is 5 and "b" is 3. It also returns false with a.contains(b) – Hakantology Jun 21 '16 at 13:39
  • Please tell use what `System.out.println(Arrays.toString(a.getBytes(StandardCharsets.UTF_8)));` and `System.out.println(Arrays.toString(b.getBytes(StandardCharsets.UTF_8)));` print and also where you read these Strings, since they obviously contain stuff which doesn't belong there. – Tom Jun 21 '16 at 13:53
  • import org.apache.commons.lang3.StringUtils; public class Test { public static void main(String[] args) { String a = "00tz"; String b = "tz"; System.out.println(StringUtils.containsIgnoreCase(b, a)); System.out.println(StringUtils.containsIgnoreCase(a, b)); } } Output: false true – user3136131 Jun 21 '16 at 13:53
  • @user3136131 OP already knows how this library works. – Tom Jun 21 '16 at 13:57
  • 1
    sorry didn;t see updates. maybe debugging the call of the method will help. – user3136131 Jun 21 '16 at 14:06
  • @Tom Hi! These are the results: a: [-17, -69, -65, 48, 48, 118, 119] b: [-17, -69, -65, 118, 119] Im reading this values from a .txt file which contains several values like this. I read it in this way: File fileA = new File("test/a.txt"); File fileB = new File("test/b.txt"); lista = (ArrayList) FileUtils.readLines(fileA, "utf-8"); listb = (ArrayList) FileUtils.readLines(fileB, "utf-8"); – Hakantology Jun 21 '16 at 14:15
  • 1
    These bytes are the [BOM](https://en.wikipedia.org/wiki/Byte_order_mark). There are several questions here on StackOverflow to remove them (`-17`, `-69`, `-65` are the bytes for `\uFEFF`). – Tom Jun 21 '16 at 14:58
  • @Tom Hi it worked thank you. You can add it as answer. – Hakantology Jun 21 '16 at 15:28

0 Answers0