You're here: Snippet Directory » Microsoft .NET » C# (33)
Language:

Datei einlesen und als ArrayList Zeile für Zeile zurückliefern

Language: Deutsch
Programming Language: C#
Published by: Thomas
Last Update: 6/30/2006
Views: 2330

License: Public Domain

Description

Liest eine Datei ein und gibt diese, leere Zeilen ausgenommen, als ArrayList (für jede Zeile ein Eintrag) zurück.

Code

1 private ArrayList ReadFile(string filename) 2 { 3 4 ArrayList dataList = new ArrayList(); 5 6 if (File.Exists(path)) 7 { 8 StreamReader sr = new StreamReader(path); 9 string data = sr.ReadToEnd(); 10 sr.Close(); 11 12 if (!string.IsNullOrEmpty(data)) 13 { 14 dataList.AddRange(data.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries)); 15 } 16 } 17 18 return dataList; 19 20 }

One comment

1

statt dataList.AddRange(data.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries)); geht auch anstelle von new string[] { "\r\n" }

new string[] { Environment.NewLine }

Monday, July 10, 2006 10:22:20 AM from dr4g0n76

Add a comment

Name *  

Email (won't be displayed) *    

Website  

Comment *  

Sicherheitscode Security Code *    

RSS