Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Warning

Looking for the documentation on the newest versions of SIL Engine and the Simple Issue Language for Jira 8 for Server/Data Center? Click here !

Info
titleAvailability

This routine is available since katl-commons starting with SIL Engine™ 4.0.8.

Syntax

...

readFromCSVFile(path, hasHeader [, charset])

Description

...

Excerpt

Read Reads the text values from the CSV file, returning them to an array, of N rows * M columns values.

Parameters

...

Parameter name

Type

Required

Description

path

string

Yes

Specifies the file name to read from.

hasHeaderbooleanYesSpecifies if the file has header.
charsetstringNoSpecifies the charset used to read that file.

Return type

...

string []

The text of the file 

 

...

values from the file, as a string array.


Example

The basic form will look like this:

Code Block
string [] fileContent = readFromCSVFile("C:/test.csv", true);

 

...


However it is hardly usable. A better form will look like this:

Code Block
//Suppose we have a CSV file with 3 columns, First Name, Last Name, Age

struct Emp {
  string fName;
  string lName;
  number age;
}


Emp [] fileContent = readFromCSVFile("C:/test.csv", true);

for(Emp e in fileContent) {
  //we can address them now in a better way .... so process row after row
  string s = e.fName + " " + e.lName + " / " + e.age;
  //do smth with that 's'
}

Unless calendar dates are in formats SIL can understand, dates should be imported as strings and further parsed afterwards in your SIL program.

Notes

Note
  1. You can use absolute paths and relative paths to "sil.home".
  2. If the header exist, it must not have duplicated columns, otherwise you need to skip it manually.
  3.  If If the file is not found, an error will be raised.

See also

...

Filter by label (Content by label)
showLabelsfalse
showSpacefalse
cqllabel = "file_routines"
labelsfile_routines