0
1

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.

unity/csharp > csv文字列(改行つき)の指定の列を抜き出す処理

Last updated at Posted at 2015-08-23
動作確認
Unity 5.1.2-f1 on MacOS X 10.8.5
using System; // for StringSplitOptions.RemoveEmptyEntries
...
	private string extractCsvRow(string src, int idx)
	{
		string[] splitted = src.Split(new string[] { System.Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries);
		string res = "";
		foreach(string each in splitted) {
			string [] elements = each.Split(',');
			res = res + elements[idx] + System.Environment.NewLine;
		}
		return res;
	}

以下のように使う。

	void Start () {
		Row0.text = extractCsvRow (SampleData.data1, /* idx=*/0);
		Row1.text = extractCsvRow (SampleData.data1, /* idx=*/1);
		Row2.text = extractCsvRow (SampleData.data1, /* idx=*/2);
		Row3.text = extractCsvRow (SampleData.data1, /* idx=*/3);
		Row4.text = extractCsvRow (SampleData.data1, /* idx=*/4);
		Row5.text = extractCsvRow (SampleData.data1, /* idx=*/5);
	}

検索用キーワード

  • extract
  • csv
  • extractCsvLine

間違い

(追記 2017/06/11)

row: 行
column: 列

本来はextractCsvColumn()が正しい命名。
extractCsvRow()で多くのコードを実装してしまい、失敗。

0
1
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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?