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

Summary

Actions Summary Table

ActionsDescription
Compare(Libraries.Language.Object object)This action compares two object hash codes and returns a CompareResult.
Equals(Libraries.Language.Object object)This action determines if two objects are equal based on their hash code values.
Get(integer row, integer column)This action returns a value from a previously read in file.
GetHashCode()This action gets the hash code for an object.
GetNumberOfColumns()This action returns the number of available columns.
GetNumberOfRows()This action returns the number of available rows.
GetSeparator()This action returns the separator used by the reader.
IsConsistent()This action checks whether all rows have the same number of columns.
Read(Libraries.System.File file)This action reads in a file and puts any data found into a table.
SetSeparator(text separator)This action sets the separator used by the reader.

Actions Documentation

Compare(Libraries.Language.Object object)

This action compares two object hash codes and returns a CompareResult. The compare result is either larger if this hash code is larger than the object passed as a parameter, smaller, or equal.

Example Code

use Libraries.Language.Support.CompareResult
        Object o
        Object t
        CompareResult result = o:Compare(t)

Parameters

Return

Libraries.Language.Support.CompareResult: The Compare result, Smaller, Equal, or Larger.

Equals(Libraries.Language.Object object)

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

Example Code

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

Parameters

Return

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

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.

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

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

Parameters

Return

text: This returns a text representation of a cell.

GetHashCode()

This action gets the hash code for an object.

Example Code

Object o
        integer hash = o:GetHashCode()

Return

integer: The integer hash code of the object.

GetNumberOfColumns()

This action returns the number of available columns.

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

        columns = csvReader:GetNumberOfColumns()

Return

integer: This returns the number of columns.

GetNumberOfRows()

This action returns the number of available rows.

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

        rows = csvReader:GetNumberOfRows()

Return

integer: This returns the number of rows.

GetSeparator()

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

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

        separator = csvReader:GetSeparator()

Return

text: This returns the separator used by the reader.

IsConsistent()

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

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

        boolean consistent = csvReader:IsConsistent()

Return

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

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.

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

Parameters

SetSeparator(text separator)

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

Example Code

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

Parameters