Answers for "c# remove line from text file"

C#
0

c# remove newline from string

// Remove all newlines from the 'example' string variable
string cleaned = example.Replace("\n", "").Replace("\r", "");
Posted by: Guest on August-04-2020
0

delete the particular line in files in c#

string line = null;
string line_to_delete = "the line i want to delete";

using (StreamReader reader = new StreamReader("C:\\input")) {
    using (StreamWriter writer = new StreamWriter("C:\\output")) {
        while ((line = reader.ReadLine()) != null) {
            if (String.Compare(line, line_to_delete) == 0)
                continue;

            writer.WriteLine(line);
        }
    }
}
Posted by: Guest on March-16-2021

C# Answers by Framework

Browse Popular Code Answers by Language