Here you can find the source of addEscapeChar(String str)
Description:Convert string which contains '%','_' to '\%' and '\_'
Parameter | Description |
---|---|
input | string |
public static String addEscapeChar(String str)
//package com.java2s; /*/* w ww . j a v a 2 s . c om*/ * $RCSfile: LogStringUtil,v $$ * $Revision: 1.0 $ * $Date: 2010-12-09 $ * * Copyright (C) 2011 GyTech, Inc. All rights reserved. * * This software is the proprietary information of GyTech, Inc. * Use is subject to license terms. */ public class Main { /** * <p>Description:Convert string which contains '%','_' to '\%' and '\_'</p> * @param input string * @return output string */ public static String addEscapeChar(String str) { String output = str.replaceAll("%", "\\\\" + "%"); output = output.replaceAll("_", "\\\\" + "_"); return output; } }