Java String Quote quoteSpecial(String orig)

Here you can find the source of quoteSpecial(String orig)

Description

Quote all "special" characters in a query.

License

Open Source License

Parameter

Parameter Description
orig starting starting

Return

orig with stuff like single quotes backslashes quoted.

Declaration

public static String quoteSpecial(String orig) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2010 Gregory Smith (gsmithfarmer@gmail.com).
 * 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
 * //from w w  w  .jav  a 2s .  co m
 * Contributors:
 *     Gregory Smith (gsmithfarmer@gmail.com) - initial API and implementation
 ******************************************************************************/

public class Main {
    /**
     * Quote all "special" characters in a query.
     * 
     * @param orig starting starting
     * @return orig with stuff like single quotes backslashes quoted.
     */
    public static String quoteSpecial(String orig) {
        if (null == orig) {
            return null;
        }

        return orig.replace("\\", "\\\\").replace("'", "\\'");
    }
}

Related

  1. quotes(CharSequence stringToQuote)
  2. quotes(CharSequence stringToQuote, boolean escapeQuote)
  3. quotes(String str)
  4. quotesEscape(String text)
  5. QuoteSingle(String S)
  6. quoteSpecialCharacters(final String oldString)
  7. quoteSQL(String string)
  8. quoteSqlIdentifier(String identifier)
  9. quoteSqlIdentifier(String name)