readTable functions

Syntax

  • string[] readStringTable(filePath)
  • float[] readFloatTable(filePath)

Parameters

  1. filePath—string
    Name of the table file to read. See Asset Search for information about search locations. Supported extension is .csv.

Returns

The content of filePath as a 2D array.

Description

The readTable functions read the CSV file filePath into a 2D array. The delimiter is detected automatically; common delimiters (including commas, semi-colons, tabs, and spaces) will work. Supported encodings are ASCII, UTF-8 and UTF-16. Unprintable control characters are replaced with '?'. The float version readFloatTable is equivalent to floatArray(readStringTable(....)) but the converted table is cached.

Related

Example

CGA code

file = "/general/assets/text/floorData.csv"
const table      = readStringTable(file)
const floatTable = readFloatTable(file)

CGARef-->
	print("Table (strings)")
	print(table)
	print("element at row 1, col 4: " + table[1, 4])
	print("Table (float)")
	print(floatTable)
	print("element at row 1, col 4: " + floatTable[1, 4])

Result

Table (strings)
(6x5)
   Floor   Height     Color      Usage   Setback
       0       10   #00FF00       Pomp       0.5
       1        7   #0000FF   Helpdesk      0.75
       2        5   #AAAAAA      Party      0.75
       3        5   #AAAAAA      Party      0.75
       4        7   #FF0000     Living       0.1
element at row 1, col 4: 0.75
Table (float)
(6x5)
   nan   nan   nan   nan    nan
     0    10   nan   nan    0.5
     1     7   nan   nan   0.75
     2     5   nan   nan   0.75
     3     5   nan   nan   0.75
     4     7   nan   nan    0.1
element at row 1, col 4: 0.75


In this topic