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();

Recommended Answers

All 3 Replies

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.

So which code is the one you're using? this one or the one here?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.