Replace the Field in a txt File

New to 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","WC3456","lastName","Hollman"

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:

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.FullName))
                                   parser.Delimiters = new string[] { "," };
                                parser.HasFieldsEnclosedInQuotes = 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("careType","");

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

You probably want to use Except() on the array; e.g. -
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualBasic.FileIO;

namespace EE_Q28907159
	class Program
		static void Main(string[] args)
			List<string> results = new List<string>();
			using (TextFieldParser parser = new TextFieldParser("EE_Q28907159.txt") { Delimiters = new[] { "," }, HasFieldsEnclosedInQuotes = true })
				while (!parser.EndOfData)
					string[] row = parser.ReadFields();
					results.Add(string.Join(",", row.Except(new[] {"caretype", "company", "carenumber", "abccomapny", "lastname"}, StringComparer.OrdinalIgnoreCase).ToArray()));

			foreach (var result in results)

Open in new window

Which produces the following output -Capture.JPGYou just want to place the *key* fields into the new array that is passed to the Except method; e.g. -
FieldRow = FieldRow.Except(new[] {"caretype", "company", "carenumber", "abccomapny", "lastname"}, StringComparer.OrdinalIgnoreCase).ToArray();

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
SaraDobAuthor Commented:
Thank you!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.