package cn.test;
public class Test {
public static void main(String[] args) {
String ips = "19.2.128.*;124.225.*.32;124.225.65.30";
String[] results = ips.split(";");
String dysqlString = "";
StringBuffer tmp = new StringBuffer();
int k = 0;
for (String string : results) {
if (k == results.length - 1) {
if (string.contains("*")) {
int position = string.indexOf("*");
tmp.append("(left(localip,"+(position-1)+") = '" + string.substring(0, position-1) + "' or left(foreightip," + (position - 1)+") = '" + string.substring(0, position-1) +"') ");
} else {
tmp.append("(localip='"+string.trim()+"' or foreigip='" + string.trim() + "') ");
}
break;
}
if (string.contains("*")) {
int position = string.indexOf("*");
tmp.append("(left(localip,"+(position-1)+") = '" + string.substring(0, position-1) + "' or left(foreightip," + (position - 1)+") = '" + string.substring(0, position-1) +"') or ");
} else {
tmp.append("(localip='"+string.trim()+"' or foreigip='" + string.trim() + "') or ");
}
k++;
}
dysqlString = tmp.toString();
System.out.println(dysqlString);
}
}
|