Here you can find the source of quoteString(final String str)
Parameter | Description |
---|---|
str | the input string |
public static String quoteString(final String str)
//package com.java2s; //License from project: Open Source License public class Main { /**/* w ww . j a v a 2 s . c o m*/ * Surround the string with single quotes, and backquote any * single quotes in the string. * * @param str the input string * @return the quoted string */ public static String quoteString(final String str) { // Check the input if (str == null) { // It's null, so just return that return "null"; } String outStr = str.replace("\"", "\\\""); if (outStr.contains("\n") || outStr.contains(",")) { outStr = "\"" + outStr + "\""; } return outStr; } }