作者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
1F:推 cloudsan:你应该要把words变成一个string[][]或是list<string[]> 12/06 16:46
2F:→ BWF:感谢大家,这个问题已经解决了,解决方式↓ 12/06 17:01
3F:→ BWF:使用ArrayList、AddRange,就可以完成了 12/06 17:02