Here you can find the source of quoteD(String s)
Parameter | Description |
---|---|
s | The input string. |
public static String quoteD(String s)
//package com.java2s; /******************************************************************************* * Copyright (c) 2012 Firestar Software, Inc. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors://from w w w . j av a 2 s . c om * Firestar Software, Inc. - initial API and implementation * * Author: * Gabriel Oancea * *******************************************************************************/ public class Main { /** * Take a string and delimit it with double quotes. If there are any double quotes in the string escape them. For * example: * <p> * <code>Arthur has a 36" sword</code> * <p> * becomes: * <p> * <code>"Arthur has a 36"" sword"</code> * * @param s The input string. * @return The double quotes delimited string; if the input is null returns null. */ public static String quoteD(String s) { return quoteImpl(s, '\"'); } private static String quoteImpl(String s, char delim) { if (s == null) return null; StringBuffer sb = new StringBuffer(s.length() + 3); // two delims one // magic sb.append(delim); for (int i = 0; i < s.length(); i++) { char c = s.charAt(i); if (c == delim) sb.append(delim); sb.append(c); } sb.append(delim); return sb.toString(); } }