I have a Db column where I need to split the resultset by '|'. I need to get the second value for each row that is populating
String example
First row 34567|001
Second row 34545|002
I want to get 001 and 002 and I want to check whether I am getting 001 and 002.
String[] res = TBOOKER_TRD_INTFTable.getString("EXT_T_ID_C").split("|");
System.out.println(res);
String [] version=res.replaceAll("\\s", "").split("|",0);
List ves=Arrays.asList(version);
System.out.println(ves);
if(ves.contains("001") && (ves.contains("002")){
System.out.println("version is correct");
}
CodePudding user response:
Just split the column value on pipe and then check the second value:
boolean correct = false;
String[] parts = TBOOKER_TRD_INTFTable.getString("EXT_T_ID_C").split("\\|");
if (parts.length > 1) {
if ("001".equals(parts[1]) || "002".equals(parts[1])) {
correct = true;
}
}
CodePudding user response:
refactor your code to this.
String result =" 34567|001";
String secondValue = result.split("\\|")[1];
if(secondValue.equals("001")||secondValue.equals("002")){
//to something with the results
}
CodePudding user response:
You can loop through your result and then just split like below
let result = "34567|001"; //If its an array/object data just loop through it to get the result
console.log(result.split('|')); //['34567', '001']
let value = result.split('|')[1]) //001
once you got the value you can compare value with your data by using if-else or using in_array if you want to check from an array