Java CSV from sanitizeListForCsv(List strList)

Here you can find the source of sanitizeListForCsv(List strList)

Description

Sanitizes the list of strings for comma-separated values (CSV) file output.<br> We follow the definition described by RFC 4180:<br> http://tools.ietf.org/html/rfc4180

License

Open Source License

Declaration

public static List<String> sanitizeListForCsv(List<String> strList) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.ArrayList;

import java.util.Iterator;
import java.util.List;

public class Main {
    /**//from   w w w. j  a  v  a2  s  .c  om
     * Sanitizes the list of strings for comma-separated values (CSV) file output.<br>
     * We follow the definition described by RFC 4180:<br>
     * {@link http://tools.ietf.org/html/rfc4180}
     */
    public static List<String> sanitizeListForCsv(List<String> strList) {
        List<String> sanitizedStrList = new ArrayList<String>();

        Iterator<String> itr = strList.iterator();
        while (itr.hasNext()) {
            sanitizedStrList.add(sanitizeForCsv(itr.next()));
        }

        return sanitizedStrList;
    }

    /**
     * Sanitizes the string for comma-separated values (CSV) file output.<br>
     * We follow the definition described by RFC 4180:<br>
     * {@link http://tools.ietf.org/html/rfc4180}
     */
    public static String sanitizeForCsv(String str) {
        return "\"" + str.replace("\"", "\"\"") + "\"";
    }
}

Related

  1. ListtoCSV(List thelist, String sep)
  2. listToCSVString(List list)
  3. listToCsvTags(List tagsList)
  4. parseCSVList(String csv)
  5. parseCsvList(String csvList)
  6. toCsv(final List list)
  7. toCsv(List list)
  8. toCsv(List list)
  9. toCsv(List strs)