Here you can find the source of toCsvString(String text, char separator, char quote, String quoteEscaped)
public static String toCsvString(String text, char separator, char quote, String quoteEscaped)
//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 } }