package com.geostar.geosmarter;
public class Test05 {
public static String[] escape = new String[] {"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"
,"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"};
public static String getFuzzyQueryValue(String oldValue) {
String escapeCharacter = null;
for (int i = 0; i < escape.length; i++) {
if (oldValue.indexOf(escape[i]) == -1) {
escapeCharacter = escape[i];
break;
}
}
if (escapeCharacter != null) {
if (oldValue.indexOf("%") != -1) oldValue = oldValue.replaceAll("%", escapeCharacter+"%");
if (oldValue.indexOf("_") != -1) oldValue = oldValue.replaceAll("_", escapeCharacter+"_");
if (oldValue.indexOf("^") != -1) oldValue = oldValue.replaceAll("_", escapeCharacter+"^");
if (oldValue.indexOf("\\[") != -1) oldValue = oldValue.replaceAll("\\[", escapeCharacter+"[");
if (oldValue.indexOf("\\]") != -1) oldValue = oldValue.replaceAll("\\]", escapeCharacter+"]");
}
oldValue = "'%" + oldValue + "%'";
if (oldValue.indexOf(escapeCharacter) != -1) oldValue = oldValue + " ESCAPE '" + escapeCharacter + "'";
return oldValue;
}
public static void main(String[] args) {
String fuzzyQueryValue = getFuzzyQueryValue("测试%_*#^模型");
System.out.println(fuzzyQueryValue);
}
}