Reads lines separated by vertical bars : FileStream : File Stream C# Source Code


Custom Search

C# Source Code » File Stream » FileStream »

 

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
*/

           
       
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo File Stream
» FileStream