Skip to end of banner
Go to start of banner

readFromCSVFile

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 3 Next »


Availability

This routine is available starting with katl-commons 4.0.8.

Syntax

readFromCSVFile(path, hasHeader [, charset])

Description

Read the values from the CSV filem, returning them into 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 values from the file, as a string array.

 

Example

On it's basic form, the routine can be used like simply:

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


However, in its bare form is hardly usable. A better usage is exemplified below:


//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 calendaristic dates are in formats SIL can understand, dates should be imported as strings and further parsed afterwards in your SIL program.


Notes

  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 the file is not found, an error will be raised.

See also

  • No labels