We help IT Professionals succeed at work.
Get Started

Replace the Field in a txt File

SaraDob
SaraDob asked
on
56 Views
Last Modified: 2016-01-05
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","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:
 "HomeCare","WC3456","Hollman"

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","");


                                                        }
                                 
                                         
                                     }
                              }
Comment
Watch Question
Developer
CERTIFIED EXPERT
Distinguished Expert 2019
Commented:
This problem has been solved!
Unlock 1 Answer and 2 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE