المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : How to read multiple lines from a file and save them into one variable (to be saved i



C# Programming
04-07-2009, 11:21 AM
Hi all,

I'm reading files from a certain folder and save everything into the database. I have a problem of reading multiple lines for a certain heading in a file and save them into one variable (to be saved into the database later).

e.g File content looks like this:

1. Date of Transaction :
20030728

2. Type of funds :
_Cash

3. Amount of Transaction(s) in Rand Value:
13500.00

4. Currency :
ZAR

PART H: List of available documents
Deal slip
Moneygram form
Copy of ID
BOP form
Gift declaration

I'm reading each line and save the value into a variable to be saved in the databse. e.g:

while ((line = reader.ReadLine()) != null)
{
if (line != null && line.Contains("1. Date of transaction :"))
{
line = reader.ReadLine();
DateOfTransaction = line;
line = reader.ReadLine();
}
if (line != null && line.Contains("2. Type of funds :"))
{
line = reader.ReadLine();
TypeOfFunds = line;
line = reader.ReadLine();
}
if (line != null && line.Contains("3. Amount of Transaction(s) in Rand Value:"))
{
line = reader.ReadLine();
AmountOfTransaction = line;
line = reader.ReadLine();
}
if (line != null && line.Contains("4. Currency :"))
{
line = reader.ReadLine();
Currency = line;
line = reader.ReadLine();
}
if (line != null && line.Contains("PART H: List of available documents :"))
{
line = reader.ReadLine();
PartHListOfAvailableDocs = line;
line = reader.ReadLine();
}
}

Heading (PART H: List of available documents) from the file is having multiple lines underneath it. How do I read each line and save them all in variable 'PartHListOfAvailableDocs'.

I'd really appreciate your help in this regard.

Thanks.