Java String Split by Comma splitDoubleParentCommas(String input)

Here you can find the source of splitDoubleParentCommas(String input)

Description

split Double Parent Commas

License

Open Source License

Declaration

public static List<String> splitDoubleParentCommas(String input) throws Exception 

Method Source Code


//package com.java2s;
/*/* w w w.ja v  a2s .c  o m*/
LWKT - A light WKT parser written in Java
    
Copyright (C) 2011 Francesco Cutruzzula' (www.cutruzzula.it)
    
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
    
This library 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
Lesser General Public License for more details.
    
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */

import java.util.ArrayList;
import java.util.List;

public class Main {
    public static List<String> splitDoubleParentCommas(String input) throws Exception {
        List<String> results = new ArrayList<String>();

        if (input.charAt(0) != '(' || input.charAt(1) != '(' || input.charAt(input.length() - 2) != ')'
                || input.charAt(input.length() - 1) != ')') {
            throw new Exception("Invalid input");
        }

        String parts[] = input.substring(2, input.length() - 2).split("\\)\\)\\s*,\\s*\\(\\(");

        for (int i = 0; i < parts.length; i++) {

            if (parts[i].trim().length() > 0) {
                results.add(parts[i].trim());
            }

        }

        return results;
    }
}

Related

  1. splitCommand(String command)
  2. splitCommand(String command)
  3. splitCommandString(String command_string)
  4. splitCommaSequence(String argumentString)
  5. splitCommaStr(String commaStr)
  6. splitOnComma(String cs)
  7. splitWithCommaOrSemicolon(String src)