Java String Tokenize extractTokens(String strStartToken, String strEndToken, String strExpression)

Here you can find the source of extractTokens(String strStartToken, String strEndToken, String strExpression)

Description

extract Tokens

License

Open Source License

Declaration

public static ArrayList<String> extractTokens(String strStartToken, String strEndToken, String strExpression) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2013 SirLordT <sirlordt@gmail.com>.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Public License v2.0
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 * /*from   www  .  j a  v  a 2  s  . co  m*/
 * Contributors:
 *     SirLordT <sirlordt@gmail.com> - initial API and implementation
 ******************************************************************************/

import java.util.ArrayList;

public class Main {
    public static ArrayList<String> extractTokens(String strStartToken, String strEndToken, String strExpression) {

        ArrayList<String> Result = new ArrayList<String>();

        if (strExpression.contains(strStartToken)) {

            String strTmp = strExpression;

            int intStartIndex = strTmp.indexOf(strStartToken); //"${" );
            int intEndIndex = strTmp.indexOf(strEndToken); //"}$" );

            while (intStartIndex > 0 && intEndIndex > intStartIndex) {

                if (intEndIndex > intStartIndex) {

                    String strCallToAdd = strTmp.substring(intStartIndex + strStartToken.length(), intEndIndex);

                    Result.add(strCallToAdd);

                    strTmp = strTmp.replace(strStartToken + strCallToAdd + strEndToken, ""); //"${" + strCallToAdd + "}$", "" );

                }

                intStartIndex = strTmp.indexOf(strStartToken); // "${" );
                intEndIndex = strTmp.indexOf(strEndToken); //"}$" );

            }

        }

        return Result;

    }
}

Related

  1. conservativeTokenize(String text)
  2. countCommonTokens(String string1, String string2)
  3. escapedTokens(String s, char separator)
  4. extractTokens(String text, String delim)
  5. getAllTokens(final String string)
  6. getCommandTokens(String commandString)
  7. getFileName(StringTokenizer s)