Java Utililty Methods CSV String Create

List of utility methods to do CSV String Create

Description

The list of methods to do CSV String Create are organized into topic(s).

Method

StringtoCsvLine(final String[] parts)
Turns a string array into a CSV line.
final StringBuffer line = new StringBuffer("");
for (final String part : parts) {
    if (line.length() > 0) {
        line.append(CSV_DELIMITER);
    line.append(part.replaceAll(CSV_QUOTE, CSV_QUOTE + CSV_QUOTE));
return line.toString();
...
StringtoCSVString(double[] d)
to CSV String
String ret = "";
for (int i = 0; i < d.length; i++) {
    ret += d[i] + ";";
ret = ret.substring(0, ret.length() - 1);
return ret;
StringtoCsvString(Object object)
to Csv String
if (object != null) {
    return "\"" + object.toString().replace("\\", "\\\\").replace("\'", "\\\'").replace("\"", "\\\"")
            + "\"";
} else {
    return "\\N";
StringtoCSVString(Object[] pStringArray)
Converts a string array to a string of comma-separated values.
return toCSVString(pStringArray, ", ");
StringtoCSVString(String s)
to CSV String
StringBuilder sb = new StringBuilder(s.length() + 1);
sb.append('\'');
int len = s.length();
for (int i = 0; i < len; i++) {
    char c = s.charAt(i);
    switch (c) {
    case '\0':
        sb.append("%00");
...
StringtoCsvString(String text, char separator, char quote, String quoteEscaped)
to Csv String
boolean containLineSeparator = text.indexOf("\n") != -1 && text.indexOf("\r") != -1;
boolean containSeparator = text.indexOf(separator) != -1;
if (containLineSeparator || containSeparator || text.startsWith("" + quote)) {
    text = text.replace("" + quote, quoteEscaped);
    return quote + text + quote;
} else {
    return text;
StringtoCsvString(String text, String splitString, String replaceSplitChar)
csv value cracch quot if it contain a line-separator.
boolean containLineSeparator = text.indexOf("\n") != -1;
if (!containLineSeparator) {
    containLineSeparator = text.indexOf("\r") != -1;
text = text.replace(splitString, replaceSplitChar);
if (containLineSeparator) {
    text = text.replace("\"", "\"\"");
    return "\"" + text + "\"";
...
StringtoCSVString(String[] fields)
to CSV String
StringBuilder b = new StringBuilder();
for (String fld : fields) {
    if (b.length() > 0) {
        b.append(',');
    String field = escapeString(fld, new char[] { '\"' }, '\"'); 
    b.append('\"').append(field).append('\"');
return b.toString();