Here you can find the source of quoteReplacement(String s)
public static String quoteReplacement(String s)
//package com.java2s; /******************************************************************************* * Copyright (c) 2004 Andrei Loskutov.//from ww w. ja va 2s . c o m * All rights reserved. This program and the accompanying materials * are made available under the terms of the BSD License * which accompanies this distribution, and is available at * http://www.opensource.org/licenses/bsd-license.php * Contributor: Andrei Loskutov - initial API and implementation *******************************************************************************/ public class Main { public static String quoteReplacement(String s) { if (s.indexOf('\\') == -1 && s.indexOf('$') == -1) { return s; } int length = s.length(); StringBuffer sb = new StringBuffer(length + 10); for (int i = 0; i < length; i++) { char c = s.charAt(i); if (c == '\\') { sb.append('\\').append('\\'); } else if (c == '$') { sb.append('\\').append('$'); } else { sb.append(c); } } return sb.toString(); } public static int indexOf(String line, char c, int startOffset, int stopOffset, boolean forward) { int i = startOffset; while (forward ? i < stopOffset : i > stopOffset) { if (line.charAt(i) == c) { return i; } if (forward) { i++; } else { i--; } } return -1; } }