Java String Quote quoteForCsv(final String field)

Here you can find the source of quoteForCsv(final String field)

Description

Inserts quotation marks around a field if it contains commas

License

Open Source License

Parameter

Parameter Description
field the field

Return

the field that is ready for inserting into a CSV line

Declaration

private static String quoteForCsv(final String field) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**/*from  w  ww . ja  v a 2  s  .c  om*/
     * Inserts quotation marks around a field if it contains commas
     *
     * @param field
     *         the field
     *
     * @return the field that is ready for inserting into a CSV line
     */
    private static String quoteForCsv(final String field) {
        if (field != null && field.contains(",")) {
            return "\"" + field + "\"";
        }
        return field;
    }
}

Related

  1. quoteEscaped(String input)
  2. quoteExecutable(String executable)
  3. quoteFileName(String filename)
  4. quoteForBatchScript(String arg)
  5. quoteForCommandString(String s)
  6. quoteForHTML(String toQuote)
  7. quoteForMdx(StringBuilder buf, String val)
  8. quoteForRegEx(String input)
  9. quoteForXML(String from)