Here you can find the source of toCsv(String value)
Parameter | Description |
---|---|
value | a parameter |
public static String toCsv(String value)
//package com.java2s; public class Main { /**// w w w.j a v a 2s .c om * Formats a string for CSV escaping it as a double quoted CSV string if necessary * @param value */ public static String toCsv(String value) { if (value.contains(",")) { return "\"" + escapeQuotesForCsv(value) + "\""; } else { return value; } } /** * Escapes quotes in a string for use in a double quoted CSV string * @param value * @return */ private static String escapeQuotesForCsv(String value) { if (value.contains("\"")) { return value.replace("\"", "\"\""); } else { return value; } } }