hello

i need to replace data only in one(specific ) column of csv file

for example

replace just in city column

f_name,l_name ,city,country --->headers

david,d,los-ang''elses,california ( replace los-ang''elses to los-ang'elses) ''-->'

g''armin ,dsdsd,new-york,sdasdas

my code is replace all the data in file , but i need to replace specific column : pls help me :-)

 Encoding encode = System.Text.Encoding.Default;
            /// Encoding encode = System.Text.Encoding.GetEncoding(1252); 



            ///StreamReader reader = new StreamReader(filePath, encode);
            StreamReader reader = new StreamReader(clsStatVar.inputFile, encode);

            string content = reader.ReadToEnd();
            reader.Close();

            ///content = Regex.Replace(content, searchText, replaceText);
            ///content = Regex.Replace(content, @"""", " ");
            ///content= Regex.Replace(content, ".", " ");
            ///
            string[] BadCharacters = { @"""", "'", "." };

            int i;
            for (i = 0; i < 3; i++)
            {
                content = content.Replace(BadCharacters[i], " ");
            }
            ///content = Regex.Replace(content, "'", " ");
            StreamWriter writer = new StreamWriter(clsStatVar.outputFile);
            writer.Write(content);
            writer.Close();

Read file line by line. Split line. Take Nth item and replace bad chars. Reconstruct line and write to new file. Optionally remove old file.

This article has been dead for over six months. Start a new discussion instead.