Here you can find the source of substituteText(String text, String token, String substitute)
text
where any occurence of token
is replaced by substitute
.
public static String substituteText(String text, String token, String substitute)
//package com.java2s; /*/*from www.j ava2s . co m*/ * Util in org.jpws.front.util * file: Util.java * * Project Jpws-Front * @author Wolfgang Keller * Created 28.09.2004 * Version * * Copyright (c) 2005 by Wolfgang Keller, Munich, Germany * This program is not freeware software but copyright protected to the author(s) stated above. However, you can use, redistribute and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2 of the License. This program 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 this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA, or go to http://www.gnu.org/copyleft/gpl.html. */ public class Main { /** Renders a string based on <code>text</code> where any occurence of * <code>token</code> is replaced by <code>substitute</code>. * @return String */ public static String substituteText(String text, String token, String substitute) { int index; if (token == null || substitute == null || (index = text.indexOf(token)) < 0) return text; while (index > -1) { text = text.substring(0, index) + substitute + text.substring(index + token.length()); index = text.indexOf(token); } return text; } }