I have a program with a GUI where I insert a couple of hexes (String), press the search button, and I find the code for it. I import the all the hexes I have a code for from a CSV file. The thing I want is that if I enter for example: 11 D7 E2 FA
, my program would only search for the 2nd nibbles, x
meaning ignored: x1 x7 x2 xA
, and if it finds something like that in the CSV it gives me the code for it. This is what I have so far, this only finds me the cases when the strings match.
codeOutputField.setText("");
String input = hexEntryField.getText();
try {
br = new BufferedReader(new FileReader(FIS));
while ((line = br.readLine()) != null) {
code = line.split(csvSplitBy);
if (input.equals(code[0])) {
codeOutputField.setText(code[1]);
}
}
}
Sample CSV:
01 5F 1E CE,0055
01 5F 13 D0,0062
01 5E 36 FE,0101
00 5E 36 FF,1002
This is the code that works for me now, wanted to share it. Only problem I have now is that I can only run the jar
file from a bat
file, double-click does not work. I have no idea why.
String input = hexEntryField.getText();
String[] myStringArray = input.split("");
codeOutputField.setText("");
try {
br = new BufferedReader(new FileReader(FIS));
while ((line = br.readLine()) != null) {
code = line.split(csvSplitBy);
List<String> items = Arrays.asList(code[0].split(""));
System.out.println(items);
if (myStringArray[1].equals(items.get(1))
&& myStringArray[4].equals(items.get(4))
&& myStringArray[7].equals(items.get(7))
&& myStringArray[10].equals(items.get(10))) {
codeOutputField.setText(code[1]);
}
}
}