Android String Array to CSV Convert concatByCSV(String[] strs)

Here you can find the source of concatByCSV(String[] strs)

Description

concat By CSV

Declaration

public static String concatByCSV(String[] strs) 

Method Source Code

//package com.java2s;

import java.util.List;

public class Main {
    public static String concatByCSV(String[] strs) {
        StringBuffer value = new StringBuffer();
        for (int i = 0; i < strs.length; i++) {
            String filterValue = new String(strs[i]);
            if (filterValue.indexOf(",") != -1) {
                if (filterValue.indexOf("\"") != -1) {
                    filterValue = filterValue.replaceAll("\"", "\"\"");
                }//from  ww w  .java  2  s .  com
                StringBuffer temp = new StringBuffer();
                temp.append("\"");
                temp.append(filterValue);
                temp.append("\"");
                filterValue = temp.toString();
            } else if (filterValue.indexOf("\"") != -1) {
                filterValue = filterValue.replaceAll("\"", "\"\"");
                StringBuffer temp = new StringBuffer();
                temp.append("\"");
                temp.append(filterValue);
                temp.append("\"");
                filterValue = temp.toString();
            }
            value.append(filterValue);
            if (i != strs.length - 1) {
                value.append(",");
            }
        }
        return value.toString();
    }

    public static String concatByCSV(List<String> strList) {
        String[] strArr = new String[strList.size()];
        return concatByCSV(strList.toArray(strArr));
    }
}