Skip to content

qie.parseCSVString

Signature: qie.parseCSVString(value, quoteValues*, quoteChar*, separator*, headerRow*, encoding*)

Returns: CSV Message csvMessage - the associated CSV message object

Parse the input string as CSV and return the associated message object.

Note

The return value CAN NEVER be assigned to the bound-in message object; it should be assigned to a locally declared variable.

Parameters

Type Name Description Default
String value the source string to be parsed
Boolean quoteValues* (optional) specifies whether or not to surround individual values with quotes true
String quoteChar* (optional) the quote character to use when surrounding values "
String separator* (optional) the separator character to use ,
Boolean headerRow* (optional) if the value contains headers as the first row false
String encoding* (optional) the character encoding for this message Source Node encoding

Example

var csvString = `
name,age,email
John Doe,28,john.doe@example.com
Jane Smith,34,jane.smith@example.com
Alice Johnson,25,alice.johnson@example.com
Bob Brown,42,bob.brown@example.com
`;
var newCsvMessage = qie.parseCSVString(csvString);
newCsvMessage.setNode('1[1]', 'David Jones');
newCsvMessage.setNode('2[1]',58);
newCsvMessage.setNode('3[1]','djones@gmail.com');
newCsvMessage.setNode('1[4]', 'Jaime B. Smith');
newCsvMessage.setNode('2[4]',22);
newCsvMessage.setNode('3[4]','smi@gmail.com');
var lastRow = Number(newCsvMessage.getRowCount());
qie.debug("num rows: " + lastRow);
newCsvMessage.setNode('1[' + (lastRow + 1) + ']', 'Robert Frost');
newCsvMessage.setNode('2[' + (lastRow + 1) + ']',32);
newCsvMessage.setNode('3[' + (lastRow + 1) + ']','frosty@yahoo.com');