Skip to content

$ps.CSV.str2csv

Overview

Converts a comma-separated string into a two-dimensional array object in the "Server Script".

Limitations

  1. All columns after conversion will be strings. No conversion to numeric or date types will be performed.
  2. The first row will not be treated as a header. The user must determine whether there is a header or not and enter the necessary processing.

Syntax

$ps.CSV.str2csv(text)

Parameters

Parameter Type Required Description
text string Yes Text

Return Value

Two-dimensional array object of string x string

Exception

If an exception occurs in C#, the exception class name and error message are placed in the Error object in the server script to generate an exception.

Usage Examples

In the following example, a string is converted into a csv object and output to the console.

JavaScript
const text = 'COLUMN01,COLUMN02,COLUMN03,COLUMN04\nA001,Japanese,TRUE,2024/12/13 0:00\nA002,Japanese,TRUE,2024/12/14 0:00\nA003,Japanese,TRUE,2024/12/15 0:00\nA004,Japanese,TRUE,2024/12/16 0:00\nA005,Japanese,TRUE,2024/12/17 0:00\n';
const csv = $ps.CSV.str2csv(text);
Operation results in the debug console
> csv
(6) [Array(4), Array(4), Array(4), Array(4), Array(4), Array(4)]
> csv.length
> 6
> csv[0].length
4
> csv[0].join()
'COLUMN01,COLUMN02,COLUMN03,COLUMN04'

Supported Versions

Supported versions Body
1.4.12.0 and later Added function