Java Scanner Usage fromStringToQuery(String value)

Here you can find the source of fromStringToQuery(String value)

Description

from String To Query

License

Open Source License

Declaration

public static String fromStringToQuery(String value) 

Method Source Code

//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;
        }
    }
}

Related

  1. countFileLines(Scanner fin)
  2. createKeyboardScanner()
  3. createScannerForString(String s)
  4. enterToContinue()
  5. equalsToIgnoreEndline(String expected, String actual)
  6. getBoolean()
  7. getChar()
  8. getConstantPoolsFromText(String text)
  9. getDirectoryString()