2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

CSVファイルの読み込み

Posted at

スクリプト

CSVLoader.cs
using UnityEngine;
using System.Collections;
using System.IO;

public class CSVLoader : MonoBehaviour {

	// Use this for initialization
	void Start () {
		int i=0, j;
		TextAsset csv = Resources.Load ("CSV/sample") as TextAsset;
		StringReader reader = new StringReader (csv.text);
		while (reader.Peek () > -1) {
			i++;
			Debug.Log (i+"回目");
			string line = reader.ReadLine ();
			string[] values = line.Split (',');
			for (j = 0; j < values.Length; j++) {
				Debug.Log (values [j]);
			}
		}
	}
}

処理の流れ

  1. TextAsset型にCSVファイルをロードする.
  2. StringReader型でCSVファイルを読むやつを作成する.
  3. reader.Peek()>-1になるまで以下の処理
  4. string line に reader.ReadLine()で一行ずつ読み込む
  5. values[]に列を格納
  6. valuesの値をどっかにいれる

注意点

  • CSVの日本語が文字化けする
    対処法探し中
  • using System.IO;
2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?