Libraries.Data.Formats.SeparatedValue Documentation

The SeparatedValue class reads in data files in a format with common separator. The most commonly used of these is the Comma Separated Value (CSV), which is the default setting.

Example Code

use Libraries.System.File
use Libraries.Data.Formats.SeparatedValue

SeparatedValue csvReader //first create the reader
File csv //then create a file
csv:SetPath("Data.csv") //set its path to a file we've created
csvReader:Read(csv) //read the csv file

Inherits from: Libraries.Language.Object

Actions Documentation

Compare(Libraries.Language.Object object)

This action compares two object hash codes and returns an integer. The result is larger if this hash code is larger than the object passed as a parameter, smaller, or equal. In this case, -1 means smaller, 0 means equal, and 1 means larger. This action was changed in Quorum 7 to return an integer, instead of a CompareResult object, because the previous implementation was causing efficiency issues.

Parameters

Return

integer: The Compare result, Smaller, Equal, or Larger.

Example

Object o
Object t
integer result = o:Compare(t) //1 (larger), 0 (equal), or -1 (smaller)

Equals(Libraries.Language.Object object)

This action determines if two objects are equal based on their hash code values.

Parameters

Return

boolean: True if the hash codes are equal and false if they are not equal.

Example

use Libraries.Language.Object
use Libraries.Language.Types.Text
Object o
Text t
boolean result = o:Equals(t)

Get(integer row, integer column)

This action returns a value from a previously read in file. It will throw an error if a file has not been properly read in.

Parameters

  • integer row: The row being accessed.
  • integer column: The column being accessed.

Return

text: This returns a text representation of a cell.

Example

use Libraries.System.File
use Libraries.Data.Formats.SeparatedValue

SeparatedValue csvReader //first create the reader
File csv //then create a file
csv:SetPath("Data.csv") //set its path to a file we've created
csvReader:Read(csv) //read the csv file

text value = csvReader:Get(1, 3) //access the item at row 1, column 3

GetHashCode()

This action gets the hash code for an object.

Return

integer: The integer hash code of the object.

Example

Object o
integer hash = o:GetHashCode()

GetNumberOfColumns()

This action returns the number of available columns.

Return

integer: This returns the number of columns.

Example

use Libraries.System.File
use Libraries.Data.Formats.SeparatedValue

SeparatedValue csvReader //first create the reader
File csv //then create a file
csv:SetPath("Data.csv") //set its path to a file we've created
csvReader:Read(csv) //read the csv file

columns = csvReader:GetNumberOfColumns()

GetNumberOfRows()

This action returns the number of available rows.

Return

integer: This returns the number of rows.

Example

use Libraries.System.File
use Libraries.Data.Formats.SeparatedValue

SeparatedValue csvReader //first create the reader
File csv //then create a file
csv:SetPath("Data.csv") //set its path to a file we've created
csvReader:Read(csv) //read the csv file

rows = csvReader:GetNumberOfRows()

GetRow(integer row)

This action returns a value from a previously read in file. It will throw an error if a file has not been properly read in.

Parameters

  • integer row: The row being accessed.

Return

Libraries.Containers.Array: This returns an array of a row.

Example

use Libraries.System.File
use Libraries.Data.Formats.SeparatedValue

SeparatedValue csvReader //first create the reader
File csv //then create a file
csv:SetPath("Data.csv") //set its path to a file we've created
csvReader:Read(csv) //read the csv file

Array<text> values = csvReader:Get(1) //access the item at row 1, column 3

GetSeparator()

This action returns the separator used by the reader. By default, the separator is a column. This separator must be a single character.

Return

text: This returns the separator used by the reader.

Example

use Libraries.System.File
use Libraries.Data.Formats.SeparatedValue

SeparatedValue csvReader //first create the reader
File csv //then create a file
csv:SetPath("Data.csv") //set its path to a file we've created
csvReader:Read(csv) //read the csv file

separator = csvReader:GetSeparator()

GetSize()

This action returns the number of available rows.

Return

integer: This returns the number of rows.

Example

use Libraries.System.File
use Libraries.Data.Formats.SeparatedValue

SeparatedValue csvReader //first create the reader
File csv //then create a file
csv:SetPath("Data.csv") //set its path to a file we've created
csvReader:Read(csv) //read the csv file

rows = csvReader:GetSize()

IsConsistent()

This action checks whether all rows have the same number of columns. If this is the case, it returns true.

Return

boolean: This returns true if all files have an equal number of columns.

Example

use Libraries.System.File
use Libraries.Data.Formats.SeparatedValue

SeparatedValue csvReader //first create the reader
File csv //then create a file
csv:SetPath("Data.csv") //set its path to a file we've created
csvReader:Read(csv) //read the csv file

boolean consistent = csvReader:IsConsistent()

Read(text value)

This action reads in a text value and puts any data found into a table. If the data is not in a consistent format, meaning that the number of columns varies per row, then IsConsistent() will return false and obtaining a correct parse cannot be guaranteed.

Parameters

  • text value

Example

use Libraries.System.File
use Libraries.Data.Formats.SeparatedValue

SeparatedValue csvReader //first create the reader
text value = 
    "Hello, how, are, you
    1, 2, 3, 4
    2, 3, 4, 5"
csvReader:Read(value) //read the csv text

Read(Libraries.System.File file)

This action reads in a file and puts any data found into a table. If the data is not in a consistent format, meaning that the number of columns varies per row, then IsConsistent() will return false and obtaining a correct parse cannot be guaranteed.

Parameters

Example

use Libraries.System.File
use Libraries.Data.Formats.SeparatedValue

SeparatedValue csvReader //first create the reader
File csv //then create a file
csv:SetPath("Data.csv") //set its path to a file we've created
csvReader:Read(csv) //read the csv file

SetSeparator(text separator)

This action sets the separator used by the reader. This action must be called before the Read(File) action.

Parameters

  • text separator: This sets the separator for the reader.

Example

use Libraries.System.File
use Libraries.Data.Formats.SeparatedValue

SeparatedValue csvReader //first create the reader
csvReader:SetSeparator("?") //set the separator to a question mark

File csv //then create a file
csv:SetPath("Data.csv") //set its path to a file we've created
csvReader:Read(csv) //read the csv file