Java CSV String Create toCsvString(String text, char separator, char quote, String quoteEscaped)

Here you can find the source of toCsvString(String text, char separator, char quote, String quoteEscaped)

Description

to Csv String

License

Apache License

Declaration

public static String toCsvString(String text, char separator, char quote, String quoteEscaped) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    public static String toCsvString(String text, char separator, char quote, String quoteEscaped) {
        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);//escaped
            return quote + text + quote;
        } else {//
            return text;
        }//from   w  ww.  j av a2 s  . c  o  m
    }
}

Related

  1. toCsvLine(final String[] parts)
  2. toCSVString(double[] d)
  3. toCsvString(Object object)
  4. toCSVString(Object[] pStringArray)
  5. toCSVString(String s)
  6. toCsvString(String text, String splitString, String replaceSplitChar)
  7. toCSVString(String[] fields)