作者BWF (大野狼)
看板C_Sharp
標題[問題] 文字檔使用split儲存於陣列中
時間Thu Dec 6 15:32:13 2012
目前我的程式碼如下:
ArrayList V = new ArrayList();
FileInfo txt = new FileInfo("C:\\Users\\BWF\\Desktop\\box.obj");//開啟box.obj
StreamReader read = txt.OpenText();
string line;
string[] CUT = new string[] { " " };//切割點
string[] words = new string[] { "" };
while(read.Peek() != -1)
{
line = read.ReadLine();
if (line.StartsWith("v "))
{
words = line.Split(CUT,StringSplitOptions.RemoveEmptyEntries);
}
}
for (int h = 0; h < words.Length; h++)//印出所有數值
{
Console.WriteLine(words[h]);
}
read.Close();
Console.ReadLine();
遇到的問題是,每行切割出來的值依照先後次序存放在陣列中,但每次數值都會被覆蓋,
不會依序存放。
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.134.32.71
推 cloudsan:你應該要把words變成一個string[][]或是list<string[]> 12/06 16:46
→ BWF:感謝大家,這個問題已經解決了,解決方式↓ 12/06 17:01
→ BWF:使用ArrayList、AddRange,就可以完成了 12/06 17:02