Java String Tokenize tokenizeStringWithQuotes(String line, String quoteStyle)

Here you can find the source of tokenizeStringWithQuotes(String line, String quoteStyle)

Description

Tokenizes string with quotes

License

Open Source License

Declaration

public static String[] tokenizeStringWithQuotes(String line,
        String quoteStyle) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2004, 2010 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors://from ww w  .j a  v a2s  .c  om
 * IBM - Initial API and implementation
 *******************************************************************************/

import java.util.ArrayList;

public class Main {
    /**
     * Tokenizes string with quotes
     */
    public static String[] tokenizeStringWithQuotes(String line,
            String quoteStyle) {
        ArrayList<String> allTokens = new ArrayList<String>();
        String[] tokens = line.split(quoteStyle);
        for (int i = 0; i < tokens.length; ++i) {
            if (i % 2 == 0) { // even tokens need further tokenization
                String[] sTokens = tokens[i].split("\\s+"); //$NON-NLS-1$
                for (int j = 0; j < sTokens.length; allTokens
                        .add(sTokens[j++])) {
                }
            } else {
                allTokens.add(tokens[i]);
            }
        }
        return allTokens.toArray(new String[allTokens.size()]);
    }
}

Related

  1. tokenizeQuotes(String f1)
  2. tokenizeStatement(String statement)
  3. tokenizeString(final String inputString, final String seperator)
  4. tokenizeString(String inString, char delimiter, String enclosures)
  5. tokenizeStringArray(String[] array, String token)
  6. tokenizeToStringArray(String str, String delimiters)
  7. tokenizeToStringArray(String str, String delimiters)
  8. tokenizeToStringArray(String str, String delimiters)
  9. tokenizeToStringArray(String str, String seperators)