SaraDob
asked on
Replace the Field in a txt File
Friends,
New to Asp.net programming. Begging your patience here.
Im trying to parse a txt file . The text file is a comma delimited file and the fields are enclosed in quotes.
The file has rows of data like this.
"CareType" ,"Company" ,"CareNumber", "HomeCare","ABCComapny","W C3456","la stName","H ollman"
The "keys" will always remain the same, throughout the file, only values change,And the keys are fixed in position.
Im trying to eliminate the "keys" and just retain the values like:
"HomeCare","WC3456","Hollm an"
Im using TextFieldParser to read through the fields.
I want to loop through the FieldRows and simply delete the "Key" fields and save the .txt file.
Right now i'm having this code:
using (TextFieldParser parser = new TextFieldParser(filename.F ullName))
{
parser.Delimiters = new string[] { "," };
parser.HasFieldsEnclosedIn Quotes = true;
while (!parser.EndOfData)
{
string[] FieldRow = parser.ReadFields();
//int Rowlength=FieldRow.Length;
if (FieldRow[0]=="CareType")
{
// I want to Replace the key with null or simply delete here.
//save the .txt file here.
I cant use FieldRow[0].Replace("careT ype","");
}
}
}
New to Asp.net programming. Begging your patience here.
Im trying to parse a txt file . The text file is a comma delimited file and the fields are enclosed in quotes.
The file has rows of data like this.
"CareType" ,"Company" ,"CareNumber", "HomeCare","ABCComapny","W
The "keys" will always remain the same, throughout the file, only values change,And the keys are fixed in position.
Im trying to eliminate the "keys" and just retain the values like:
"HomeCare","WC3456","Hollm
Im using TextFieldParser to read through the fields.
I want to loop through the FieldRows and simply delete the "Key" fields and save the .txt file.
Right now i'm having this code:
using (TextFieldParser parser = new TextFieldParser(filename.F
{
parser.Delimiters = new string[] { "," };
parser.HasFieldsEnclosedIn
while (!parser.EndOfData)
{
string[] FieldRow = parser.ReadFields();
//int Rowlength=FieldRow.Length;
if (FieldRow[0]=="CareType")
{
// I want to Replace the key with null or simply delete here.
//save the .txt file here.
I cant use FieldRow[0].Replace("careT
}
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER