Home>

I'm trying to make a game with Unity.
I want to read the prepared csv file,
If i try to output after reading, an error will occur.
I don't know what the error text says ...
Apparently, it seems that an error will occur if the target CSV file contains double-byte characters.
How can I insert a full-width character string into CSV and read it?
Thank you.

Index was out of range. Must be non-negative and less than the size of the collection.
What I tried

For the reading code, I referred to the following site.
Rather, I copied most of this code.
https://note.com/macgyverthink/n/n83943f3bad60

Corresponding source code
using System.Collections.Generic;
using UnityEngine;
using System.IO;
public class csv_test: MonoBehaviour
{
    TextAsset csvFile;// CSV file
    List<string []>csvDatas = new List<string []>();// List to put the contents of CSV
    void Start ()
    {
        csvFile = Resources.Load ("testCSV") as TextAsset;// Load CSV under Resouces
        StringReader reader = new StringReader (csvFile.text);
        // Read line by line while splitting with,
        // Add to the list
        while (reader.Peek ()! = -1) // Until reader.Peaek becomes -1
        {
            string line = reader.ReadLine ();// Read line by line
            csvDatas.Add (line.Split (','));//, Add to list separated by
        }
        // You can freely retrieve the value by specifying csvDatas [row] [column]
        Debug.Log (csvDatas [1] [1]);
    }
}
// No error will occur if all characters are half-width (5 is output)
1,2,3
4,5,6
// I get an error if there are double-byte characters ...
It's full-width, a few
4,5,6
Supplementary information (FW/tool version, etc.)

Unity 2018.4.28f1