Reads lines separated by vertical bars

using System;
using System.IO;
public class FileReadAddresses {
public static void Main( ) {
String line;
String street, city, state, zip;
StreamReader f = new StreamReader("test.data");
while ((line=f.ReadLine())!= null){
String[] strings = line.Split(new char[]{'|'});
if (strings.Length == 4) {
street = strings[0];
city = strings[1];
state = strings[2];
zip = strings[3];
Console.WriteLine(street);
Console.WriteLine(city);
Console.WriteLine(state);
Console.WriteLine(zip);
}
}
f.Close();
}
}
//File: test.data
/*
4665 Street|Toronto|ON|90048
*/
Related examples in the same category