Here you can find the source of fromStringToQuery(String value)
public static String fromStringToQuery(String value)
//package com.java2s; //License from project: Open Source License import java.util.Scanner; public class Main { public static String fromStringToQuery(String value) { String query = ""; boolean isOpenedQuote = false; Scanner sc = new Scanner(value); while (sc.hasNext()) { String next = sc.next(); if (next.contains("\"") || isOpenedQuote) { query += next;/*from w w w . j ava 2s . c om*/ if (next.contains("\"")) { isOpenedQuote = !isOpenedQuote; } } else { if (next.contains(":")) { query += next.replace(":", ":*") + "*"; } else { query += "*" + next + "*"; } } if (!isOpenedQuote) { query += " OR "; } else { query += " "; } } if (query.endsWith(" OR ")) { return query.substring(0, query.lastIndexOf(" OR ")); } else { return query; } } }