Java CSV String Escape csvFormat(Object... obj)

Here you can find the source of csvFormat(Object... obj)

Description

csv Format

License

Open Source License

Declaration

public static String csvFormat(Object... obj) 

Method Source Code

//package com.java2s;
/**/*from   w w w.j  a  v a 2  s  .c  o  m*/
 * Various utilities. All methods here are static.
 * 
 * @author Gregory Golberg (grisha@alum.mit.edu)
 * 
 *         Copyright ? <a href="http://www.enremmeta.com">Enremmeta LLC</a>
 *         2014. All Rights Reserved. This code is licensed under <a
 *         href="http://www.gnu.org/licenses/agpl-3.0.html">Alfero GPL 3.0</a>
 * 
 */

public class Main {
    public static String csvFormat(Object... obj) {
        String retval = "";
        for (Object o : obj) {
            if (retval.length() > 0) {
                retval += ",";
            }
            if (o == null) {
                o = "";
            }
            String s = o.toString();
            s = s.replaceAll("\\\\", "\\\\\\\\");
            s = s.replaceAll("\"", "\\\"");
            retval += "\"" + s + "\"";
        }
        return retval;
    }
}

Related

  1. csvEscape(String str)
  2. csvEscapeXML(String value)
  3. CSVFormat(String data)