The manipulation of text files can be very useful in the realization of .NET applications whether Console, it is very frequent to need to store information in a file. What we are going to do during the following code is actually learning to read on them.
file.txt:
1 2 3 4 5 |
1;Tom;Garnd 2;Mark;Bard 3;Doe;Joe |
C# Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
class Program { static void Main(string[] args) { String path = @"E:\file.txt"; var lines = File.ReadAllLines(path); for (int i = 0; i < lines.Length; i++) { var fields = lines[i].Split(';'); Console.WriteLine("number:{0} \t name:{1} \t lastname:{1}", fields[0], fields[1], fields[2]); } Console.ReadLine(); } } |
Output:
Diğer makalelerde iyi kodlama hakkında görebilirsiniz ve .net Framework’ün metin dosyası işleme alanında bize sunduğu olanaklardan yararlanın!