支撑Visual Studio C# [英] While brace Visual Studio C#
本文介绍了支撑Visual Studio C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有文本文件text.txt,其值:
1 2 3
2 2 5
2 4 6
3 5 7
3 3 8
6 2 44
每行需要放入一个字符串
我有这个代码;
I have text file text.txt with values:
1 2 3
2 2 5
2 4 6
3 5 7
3 3 8
6 2 44
Each row need to put in one string
I have this code;
StreamReader dFile = null;
dFile = new StreamReader("Broj2.txt");
char[] SPACE = new char[] {' ' };
string a = dFile.ReadLine();
string[] data = a.Split(SPACE);
int[] niz = new int[3];
niz[0] = Convert.ToInt32(data[0]);
niz[1] = Convert.ToInt32(data[1]);
niz[2] = Convert.ToInt32(data[2]);
while ( )
{
a = dFile.ReadLine();
data = a.Split(SPACE);
}
每行应该放在一个字符串中,这是我们使用help while函数逐行读取的宝贵资产.while放在括号中是什么?
请帮忙!
For each row should be put to one string, and a valuable asset that we read line by line using help while function.What goes into the bracket while?
Please help!
推荐答案
可以尝试一下...
You can try this...
// Read each line of the file into a string array. Each element
// of the array is one line of the file.
string[] lines = System.IO.File.ReadAllLines("Broj2.txt");
int[] niz = new int[3];
foreach (string line in lines)
{
string[] data = line.Split(' ');
niz[0] = Convert.ToInt32(data[0]);
niz[1] = Convert.ToInt32(data[1]);
niz[2] = Convert.ToInt32(data[2]);
}
您可以执行以下操作:
you can do something like below:
while(dFile.ReadLine())
{
a = dFile.ReadLine();
data = a.Split(SPACE);
}
这篇关于支撑Visual Studio C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文