Skip to content

Format

typescript
CSV.SetData(val)

class: CSV

Description

Set the content of the current CSV table by passing in a string that conforms to the CSV format.

Parameters

param_nametypedescription
valstringThe string to be passed in.

Return

typedescription
void

Code Example

typescript
let csv = Resources.Load<CSV>(CSV, "7524C80CF370442F0DA9F78C6E82CD4F");
if (csv == null) {
    throw new Exception("failed to load csv");
}
let str = "";
let row =  Math.trunc(Math.random() * 9 + 3);
let contentArr = new Array<Array<number>>(row);
for(let rowIdx = 0; rowIdx < row; rowIdx++){
    let col = Math.trunc(Math.random() * 9 + 3);
    contentArr[rowIdx] = new Array<number>(col);
    for(let colIdx = 0;colIdx<col;colIdx++){
        let val = Math.trunc(Math.random()*1000);
        contentArr[rowIdx][colIdx] = val;
        str += val.toString();
        str+=",";
    }
    str+="\r\n";
}
csv.SetData(str);
Debug.Log("SetData: ");
Debug.Log(str);

Debug.Log("row:1,col:1 value is : ",csv.GetItem(1, 1));