Class CSVReader
- Namespace
- NominalSystems.Universe
- Assembly
- NominalSystems.Universe.dll
This class is a helper to read CSV files in an array and be able to pull records based on elements in the table if they exist.
public class CSVReader
- Inheritance
-
CSVReader
Constructors
CSVReader(string, char)
Initialises the data from a CSV file and loads it into the data list for retrieval.
public CSVReader(string file, char delimiter = ',')
Parameters
Fields
IsValid
A flag for if the file exists or if it is invalid. If the path is wrong, then this flag will be False.
public bool IsValid
Field Value
Properties
Rows
The number of rows that exist in the CSV file
public int Rows { get; }
Property Value
Methods
FindRowWhere(string, char, double, int)
Attempts to find the first row where a particular condition is met. This could be <, = or >.
public int FindRowWhere(string header, char operation = '=', double value = 0, int decimals = 6)
Parameters
header
stringThe name of the column to look through
operation
charThe operation to use: <, = or >
value
doubleThe value to compare to
decimals
intThe number of decimal places to track
Returns
- int
The index of the row that exists. A -1 will be returned if it does not find.
GetAllDoubleData()
Returns all data as a list of doubles
public List<List<double>> GetAllDoubleData()
Returns
GetDouble(int, int)
Gets an double value from the CSV based on a coodinate from the CSV file. If no data exists, then it will return a 0.0.
public double GetDouble(int row, int col)
Parameters
Returns
- double
The data value as a double if it exists
GetDouble(string, int)
Gets an double value from the CSV based on a coodinate from the CSV file. If no data exists, then it will return a 0.0.
public double GetDouble(string column, int row)
Parameters
Returns
- double
The data value as a double if it exists
GetFloat(int, int)
Gets an floating point value from the CSV based on a coodinate from the CSV file. If no data exists, then it will return a 0.0.
public float GetFloat(int row, int col)
Parameters
Returns
- float
The data value as a float if it exists
GetInt(int, int)
Gets an integer value from the CSV based on a coodinate from the CSV file. If no data exists, then it will return a 0.
public int GetInt(int row, int col)
Parameters
Returns
- int
The data value as a int if it exists
GetString(int, int)
Gets a string from the column based on a coordinate from the CSV file. If no data exists, then it will return a null value.
public string GetString(int row, int col)
Parameters
Returns
- string
The string data if it exists
GetVector3(string, int)
Gets a Vector3 from the CSV based on the column name. This assumes that the column entered is the first and the other two columns are right next to each other.
public Vector3 GetVector3(string columnX, int row)
Parameters
Returns
- Vector3
The Vector data from that row at that column
HasColumn(string)
Returns whether a particular column exists.
public bool HasColumn(string column)
Parameters
column
stringThe name of the column
Returns
- bool
A flag for if the column exists