Here you can find the source of quote(String str)
Parameter | Description |
---|---|
str | the string to quotify |
public static String quote(String str)
//package com.java2s; /*/* w w w. ja va2 s . c o m*/ * Portions of this file Copyright 1999-2005 University of Chicago * Portions of this file Copyright 1999-2005 The University of Southern California. * * This file or a portion of this file is licensed under the * terms of the Globus Toolkit Public License, found at * http://www.globus.org/toolkit/download/license.html. * If you redistribute this file, with or without * modifications, you must include this notice in the file. */ public class Main { /** * Quotifies a specified string. * The entire string is encompassed by double quotes and each * " is replaced with \", \ is replaced with \\. * * @param str the string to quotify * @return quotified and escaped string */ public static String quote(String str) { int len = str.length(); StringBuffer buf = new StringBuffer(len + 2); buf.append("\""); char c; for (int i = 0; i < len; i++) { c = str.charAt(i); if (c == '"' || c == '\\') { buf.append("\\"); } buf.append(c); } buf.append("\""); return buf.toString(); } }