Converting an array of arrays into a CSV string
504943
function toCSVString(data, params) {
    if (data.length === 0) {
      return '';
    }
    params = params || {};

    var header = params.headers || [],
        plainObject = isPlainObject(data[0]),
        keys = plainObject && (params.order || keysIndex(data)),
        oData,
        i;

    // Defaults
    var escape = params.escape || '"',
        delimiter = params.delimiter || ',';

    // Dealing with headers polymorphism
    if (!header.length)
      if (plainObject && params.headers !== false)
        header = keys;

    // Should we append headers
    oData = (header.length ? [header] : []).concat(
      plainObject ?
        data.map(function(e) { return objectToArray(e, keys); }) :
        data
    );

    // Converting to string
    return oData.map(function(row) {
      return row.map(function(item) {

        // Wrapping escaping characters
        var i = ('' + (typeof item === 'undefined' ? '' : item)).replace(
          new RegExp(rescape(escape), 'g'),
          escape + escape
        );

        // Escaping if needed
        return ~i.indexOf(delimiter) || ~i.indexOf(escape) || ~i.indexOf('\n') ?
          escape + i + escape :
          i;
      }).join(delimiter);
    }).join('\n');
  }
153276
def csv(self, text=TEXT, sep=',', index=True, float_fmt="%.2g"):
        
        return self._data.to_csv(sep=sep, index=index, float_format=float_fmt)
149454
public static String csv(String... msgs) {
		StringBuffer buf = new StringBuffer();
		for (String msg : msgs) {
			buf.append(msg);
			buf.append("; ");
		}
		return buf.toString();
	}
1240078
def to_csv data
      attributes = data.first&.keys || []

      CSV.generate(headers: true) do |csv|
        csv << attributes

        data.each do |row|
          csv << attributes.map do |att|
            row[att]
          end
        end
      end
    end
1363439
def to_csv(args):
    
    result_file = args.result_file
    output_file = args.output_file
    delimiter = args.delimiter
    if not os.path.isfile(result_file):
        raise OSError("Results file does not exists")
    headers = ['elapsed', 'epoch', 'turret_name', 'scriptrun_time', 'error']
    headers_row = {}

    set_database(result_file, db, {})

    results = Result.select()

    for item in results:
        result_item = item.to_dict()
        for k in result_item['custom_timers'].keys():
            if k not in headers:
                headers.append(k)
                headers_row[k] = k

    with open(output_file, "w+") as f:
        writer = csv.DictWriter(f, fieldnames=headers, delimiter=delimiter)
        headers_row.update({
            'elapsed': 'elapsed time',
            'epoch': 'epoch (in seconds)',
            'turret_name': 'turret name',
            'scriptrun_time': 'transaction time',
            'error': 'error'
        })
        writer.writerow(headers_row)
        for result_item in results:
            line = result_item.to_dict()
            for key, value in line['custom_timers'].items():
                line[key] = value
            del line['custom_timers']
            writer.writerow(line)
553325
public static function arrayToCsv($array, $header_row = true, $col_sep = ",", $row_sep = "\n", $qut = '"')
    {
        if (!is_array($array) || !isset($array[0]) || !is_array($array[0])) {
            return false;
        }
        $output = '';
        if ($header_row) {
            foreach ($array[0] as $key => $val) {
                $key = str_replace($qut, "$qut$qut", $key);
                $output .= "$col_sep$qut$key$qut";
            }
            $output = substr($output, 1)."\n";
        }
        foreach ($array as $key => $val) {
            $tmp = '';
            foreach ($val as $cell_key => $cell_val) {
                $cell_val = str_replace($qut, "$qut$qut", $cell_val);
                $tmp .= "$col_sep$qut$cell_val$qut";
            }
            $output .= substr($tmp, 1).$row_sep;
        }

        return $output;
    }
986020
private static String joinString(String[] array) {
    StringBuilder sb = new StringBuilder();
    for (String value : array) {
      if (sb.length() > 0) {
        sb.append(" ");
      }
      sb.append(value);
    }
    return sb.toString();
  }
750105
def csv_array_clean_format(csv_data, c_headers=None, r_headers=None):
    

    result = []
    real_num_header = len(force_list(r_headers[0])) if r_headers else 0
    result.append([""] * real_num_header + c_headers)

    for k_index in range(0, len(csv_data)):

        if r_headers:
            result.append(
                list(
                    itertools.chain(
                        [r_headers[k_index]],
                        csv_data[k_index])))

        else:
            result.append(csv_data[k_index])

    return result
194561
private function toCsvLine(array $elements, $memory): string
    {
        ftruncate($memory, 0);
        rewind($memory);
        fputcsv($memory, $elements, $this->delimiter, $this->enclosure);
        rewind($memory);
        return stream_get_contents($memory);
    }
596510
def joinCSVs(csvFilePaths, column, ouputFileName, separator = ',') :
	
	
	res = ''
	legend = []
	csvs = []
	
	for f in csvFilePaths :
		c = CSVFile()
		c.parse(f)
		csvs.append(c)
		legend.append(separator.join(c.legend.keys()))
	legend = separator.join(legend)
	
	lines = []
	for i in range(len(csvs[0])) :
		val = csvs[0].get(i, column)
		line = separator.join(csvs[0][i])
		for c in csvs[1:] :
			for j in range(len(c)) :
				if val == c.get(j, column) :
					line += separator + separator.join(c[j])
					
		lines.append( line )
	
	res = legend + '\n' + '\n'.join(lines)
	
	f = open(ouputFileName, 'w')
	f.write(res)
	f.flush()
	f.close()
	
	return res
292774
function csvToMapping(csvString) {
  const lines = csvString.split(/\n|\r|\r\n/);
  const header = lines.shift().split(',');
  const key = header.shift();
  const now = new Date();
  const headerIdx = [];
  const fields = [];
  header.forEach((h, i) => {
    if (h === '') return;
    headerIdx.push(i);
    fields.push({key: h, format: 'text'});
  });
  const mapping = {
    created: now.toString(),
    fields: fields,
    key: key,
    mapping: {}
  };
  lines.forEach(line => {
    const values = line.split(',');
    const k = values.shift();
    mapping.mapping[k] = Array(headerIdx.length);
    headerIdx.forEach(i => {
      mapping.mapping[k][i] = values[i];
    });
  });
  return mapping;
}
898688
public function convertToCSVRecord(array $fields): string
    {
        $csv = new \SplTempFileObject();
        $csv->fputcsv($fields);
        $csv->rewind();
        return rtrim($csv->fgets(), "\r\n");
    }
346386
public function stringArrayToCsv()
    {
        $value = $this->getParameter('value');
        if (!is_array($value)) {
            $value = explode($this->getParameter('delimiter', ','), $value);
        }

        $value = array_map('trim', $value);
        if (empty($value)) {
            return '';
        }
        $value = array_filter($value, 'strlen');

        if ($this->getParameter('lowercase', false)) {
            $value = array_map('strtolower', $value);
            if ($this->getParameter('unique', true)) {
                $value = array_keys(array_flip($value));
            }
        } else {
            if ($this->getParameter('unique', true)) {
                $value = array_values(array_intersect_key($value, array_unique(array_map('strtolower', $value))));
            }
        }

        return implode(',', $value);
    }
1075290
function __serializeArrayStreaming(data, options=DEFAULT_OPTIONS) {
	let dataBuffers = [];
	// ignore undefined value
	for (let key in data) {
		let subData = data[key];
		let subType = __getType(subData, options);
		let subTypeBuffer = __serializeType(subType);
		let subDataBuffers = __serializeData(subType, subData, options);
		dataBuffers.push(subTypeBuffer, ...subDataBuffers);
	}
	return [...dataBuffers, TYPE_HEADER.ARRAY_END];
}
424943
function stringToArrayLike(str, array) {
    for (var i = 0; i < str.length; ++i) {
        array[i] = str.charCodeAt(i) & 0xFF;
    }
    return array;
}
763629
private String _serializeArray(Array array, Map<Object, String> done, String id) throws ConverterException {
	return _serializeList(array.toList(), done, id);
    }
162877
private String stringArray2String(String[] array) {
        StringBuilder sb = new StringBuilder("");
        for (int i = 0 ; i<array.length ; i++) {
            sb.append(array[i]);
            if (i<array.length - 1)
                sb.append("\n");
        }
        return sb.toString();
    }