Zoo tutorials: [ SQL | Linux | XML ]
ProgZoo: [ Java | C# | VB | C++ | Perl ]
Log in

A Gentle Introduction to
C# Programming

Reading a tab delimited file

 

Input and Output

Reading a tab delimited file

A tab delimited file has a simple structure. Every line (record) has the same number of fields. Each field is separated by the tab character.

Each line of the file cia.txt represents a country. Each has five fields:

  • name
  • region
  • area
  • population
  • gdp

A sample from cia.txt:

Lithuania	Europe	65200	3596617	45230000000
Luxembourg	Europe	2586	468571	27270000000

1. [ C# ] Splitting the fields


Big

We split the line on the tab character and copy each field into a variable with an appropriate name and an appropriate type.

In a tab delimited file we need to convert each field from a String to the appropriate type if required.

This program prints the name for every country with a large population.