unity でテキストファイルを二次元配列で読み込みたいのですが
1,2,3,4
5,6,7,8
9,10,11,12
13,14,15,16
を
[0][0]で1
[1][0]で5
が出るようにしたいのですが
以下のコードで試したところ
ArgumentOutOfRangeException: Argument is out of range.
Parameter name: index
System.Collections.Generic.List`1[System.String[]].get_Item (Int32 index) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Collections.Generic/List.cs:633)
sample.Start () (at Assets/Scenes/test/sample.cs:22)
とエラーが出でしまいました。
正直お手上げ状態です。
どなたか解決策をお願いします
C#
1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4using System.IO; 5 6public class sample : MonoBehaviour { 7 [SerializeField]public TextAsset csvFile; // GUIでcsvファイルを割当 8 List<string[]> csvDatas = new List<string[]>(); 9 10 // Use this for initialization 11 void Start () { 12 13 // 格納 14 string[] lines = csvFile.text.Replace("\r\n", "\n").Split("\n"[0]); 15 foreach (var line in lines){ 16 if (line == "") {continue;} 17 csvDatas.Add(line.Split(',')); // string[]を追加している 18 } 19 20 // 書き出し<> 21 Debug.Log (csvDatas.Count); // 行数 22 Debug.Log (csvDatas[0].Length); // 項目数 23 Debug.Log (csvDatas [1] [2]); // 2行目3列目 24 } 25} 26
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/09/04 09:22