Here you can find the source of toCsvString(String text, String splitString, String replaceSplitChar)
Parameter | Description |
---|---|
text | a parameter |
splitString | a parameter |
replaceSplitChar | usually use empty to remove splitString |
public static String toCsvString(String text, String splitString, String replaceSplitChar)
//package com.java2s; //License from project: Apache License public class Main { /**//from w w w.ja v a 2 s . co m * * csv value cracch quot if it contain a line-separator. * and that case quot string must be escaped with additional quot; * * can't read this csv from CSVReader * * @param text * @param splitString * @param replaceSplitChar usually use empty to remove splitString * @return */ public static String toCsvString(String text, String splitString, String replaceSplitChar) { 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 + "\""; } else {// return text; } } }