Created
June 12, 2012 02:02
-
-
Save NikkiBuck/2913950 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// this is the order of the fields for a book stored in a file | |
ISBN = 0; | |
AUTHORS_LAST_NAME = 1; | |
AUTHORS_FIRST_NAME = 2; | |
TITLE = 3; | |
PUBLICATION_YEAR = 4; | |
INDEX_PRICE = 5; | |
string recordIn; | |
string[] bookFields; // use this to split the line up into fields (fields are delimeted by the '\t') | |
StreamReader booksStreamReader = new StreamReader("Book.txt"); | |
while (booksStreamReader.Peek() != -1) | |
{ | |
recordIn = reader.ReadLine(); | |
// NOTE DELIM is '\t' | |
bookFields = recordIn.Split(DELIM); // YOU CAN SPLIT ANY "STRING" like this | |
// trim leading/trailing whitespace | |
bookFields[0]= bookFields[0].Trim(); | |
bookFields[1] = bookFields[1].Trim(); | |
bookFields[2] = bookFields[2].Trim(); | |
bookFields[3] = bookFields[3].Trim(); | |
bookFields[4] = bookFields[4].Trim(); | |
bookFields[5] = bookFields[5].Trim(); | |
// do what you need to do with each Book Field.. ie put in your array | |
lstBooks.Items.Add(recordIn); | |
} | |
booksStreamReader.Close(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment