Java String Split by Char SplitSearchString(String search_string, char split_char, boolean clear_exact_match_char)

Here you can find the source of SplitSearchString(String search_string, char split_char, boolean clear_exact_match_char)

Description

Splits the search string according to the following rule: 1.

License

Open Source License

Parameter

Parameter Description
search_string a parameter

Declaration

public static String[] SplitSearchString(String search_string, char split_char,
        boolean clear_exact_match_char) 

Method Source Code

//package com.java2s;
/*Copyright 2008 by Vladimir Polony, Stupy 24, Banska Bystrica, Slovakia
    /*  w  w w.  ja v a2  s. c  o m*/
This file is part of OpenRep FREE homeopathic software.
    
OpenRep FREE is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
    
OpenRep FREE is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
    
You should have received a copy of the GNU General Public License
along with OpenRep FREE.  If not, see <http://www.gnu.org/licenses/>.*/

import java.util.ArrayList;

public class Main {
    /** search string constant*/
    public static final char EXACT_MATCH_CHAR = '\"';

    /** Splits the search string according to the following rule:
     *  1. If the split_char character is inside "" -> do not split
     *
     * @param search_string
     * @return
     */
    public static String[] SplitSearchString(String search_string, char split_char,
            boolean clear_exact_match_char) {
        ArrayList<String> result = new ArrayList();
        String temps = "";
        boolean delim_start = false;
        for (int x = 0; x < search_string.length(); x++) {
            if (search_string.charAt(x) == EXACT_MATCH_CHAR) {
                delim_start = !delim_start;
                if (!clear_exact_match_char)
                    temps += search_string.charAt(x);
            } else if (search_string.charAt(x) == split_char && !delim_start) {
                temps = temps.trim();
                if (!temps.equals(""))
                    result.add(temps);
                temps = "";
            } else
                temps += search_string.charAt(x);
        }
        temps = temps.trim();
        if (!temps.equals(""))
            result.add(temps);
        String[] rslt = new String[result.size()];
        for (int x = 0; x < result.size(); x++)
            rslt[x] = result.get(x);
        return rslt;
    }
}

Related

  1. splitInclusive(CharSequence input, char[] splitChars)
  2. splitList(String source, char useChar)
  3. splitOnChar(String str, char c)
  4. splitOnChar(String str, int ch)
  5. splitOnCharArray(String value, String splitOn)
  6. splitString(final String s, final char c, final boolean trimBlanks)
  7. splitString(String str, char sep)
  8. splitString(String string, char ch)
  9. splitStringToChars(String str)