Here you can find the source of extractTokens(String strStartToken, String strEndToken, String strExpression)
public static ArrayList<String> extractTokens(String strStartToken, String strEndToken, String strExpression)
//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; } }