/* GNU General Public License CacheWolf is a software for PocketPC, Win and Linux that enables paperless caching. It supports the sites geocaching.com and opencaching.de Copyright (C) 2006 CacheWolf development team See http://www.cachewolf.de/ for more information. This program is free software; you can redistribute it 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ package CacheWolf.utils; public class STRreplace { /* Replace all instances of a String in a String. * @param s String to alter. * @param f String to look for. * @param r String to replace it with, or null to just remove it. */ public static String replace(String s, String f, String r) { if (s == null || s.equals("")) return s; if (f == null || f.equals("")) return s; if (r == null) r = ""; int index01 = s.indexOf(f); int index02 = 0; StringBuffer sb = new StringBuffer(); while (index01 != -1) { sb.append(s.substring(index02, index01)).append(r); index02 = index01 + f.length(); index01 = s.indexOf(f, index02); /* original impl. s = s.substring(0,index01) + r + s.substring(index01+f.length()); index01 += r.length(); index01 = s.indexOf( f, index01 ); */ } return sb.append(s.substring(index02)).toString(); } }