Java CSV String Convert csvToArray(String line)

Here you can find the source of csvToArray(String line)

Description

csv To Array

License

Apache License

Declaration

public static String[][] csvToArray(String line) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    public static String[][] csvToArray(String line) {
        return csvTextToArray(line, ',');
    }/*ww  w . j  a  v  a 2 s . c  o m*/

    public static String[][] csvTextToArray(String line, char separator) {
        line = toNLineSeparator(line);
        String[] lines = line.split("\n");
        String ret[][] = new String[lines.length][0];
        for (int i = 0; i < lines.length; i++) {
            String csv[] = lines[i].split("" + separator);
            ret[i] = new String[csv.length];
            for (int j = 0; j < csv.length; j++) {
                ret[i][j] = csv[j];
            }
        }
        return ret;
    }

    public static String toNLineSeparator(String text) {
        String ret = text.replace("\r\n", "\n");
        ret = ret.replace("\r", "\n");
        return ret;
    }
}

Related

  1. csvQuote(String value)
  2. csvString(Object[] objects)
  3. csvstring(Object[] str)
  4. csvTitleToTag(String title, int index)
  5. csvToArray(String dirs)
  6. csvToValuePerLine(String csv)