By Example I have a .txt File with this content:
开发者_如何学PythonHello;Test;StackOverflow;I live here
Hi;NoTest;StackOverflow;I don't live here
and so on..
Now I would like to read the txtFile, but I don't want to read the "whole" line or everthing.. only to the next semicolon.. till the end of a Line..
one StringVariable for one Word in the txtFile but just for one line..
How could I achieve this?
You can read text line by line like this:
var streamReader = new StreamReader(new FileStream("c:\\file.txt"));
var line = streamReader.ReadLine();
var values = line.Split(';');
and then read any value from line like this:
var value = values[2];
And if you want to iterate throught those values you can make it like this:
var streamReader = new StreamReader(new FileStream("c:\\file.txt"));
while(!streamReader.EndOfStream)
{
var line = streamReader.ReadLine()
var values = line.Split(';');
for(var i = 0; i < line.Length; i++)
Console.WriteLine(values[i]); //example usage
}
streamReader.Dispose();
精彩评论