String cut = "03|05|02|01|";
String acctNo = "1234|5678@2323|90123|4567|";
String type = "404002|404002@404015|404015|404014|";
//输入05,把下面对应的acctNo 和 type 取出来
默认取的是@前面的,如果发现type是404002的时候 就取后面的
String acctNo = "1234|5678@2323|90123|4567|";
String type = "404002|404002@404015|404015|404014|";
//输入05,把下面对应的acctNo 和 type 取出来
默认取的是@前面的,如果发现type是404002的时候 就取后面的
String cut = "03|05|02|01|";
String acctNo = "1234|5678@2323|90123|4567|";
String type = "404002|404002@404015|404015|404014|";
String input = "05";
String[] fields = cut.split("\\|");
int pos = -1;
for(int i=0;i<fields.length;i++){
if(fields[i].equals(input)){
pos = i;
break;
}
}
// if(pos == -1) throw new Exception .... 错误处理自己写吧
String typeValue = type.split("\\|")[pos];
boolean doSelect = false;
if(typeValue.indexOf("@") > 0){
doSelect = typeValue.substring(0, typeValue.indexOf("@")).equals("404002");
}
System.out.println(pickValue(type, pos, doSelect));
System.out.println(pickValue(acctNo, pos, doSelect));
} private static String pickValue(String in, int pos, boolean doSelect) {
String val = in.split("\\|")[pos];
if (val.indexOf("@") > 0){
if(doSelect){
return val.substring(val.indexOf("@")+1);
}else{
return val.substring(0, val.indexOf("@"));
}
}
return val;
}