Quantcast
Channel: How to change Unix Line feed to Windows Line Feed with C# - Stack Overflow
Viewing all articles
Browse latest Browse all 2

Answer by Noctis for How to change Unix Line feed to Windows Line Feed with C#

$
0
0

Because you are writing the string and overwriting it.

Try this:

string[] filePaths = Directory.GetFiles(@"c:\textfiles\", "*.txt");

foreach (string file in filePaths)
{
    string[] lines = File.ReadAllLines(file);
        List<string> list_of_string = new List<string>();
    foreach (string line in lines)
    {
        list_of_string.Add( line.Replace("\n", "\r\n"));
    }
    File.WriteAllLines(file, list_of_string);
}

Viewing all articles
Browse latest Browse all 2

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>