I want to read a textfile, change a format, and then output it in a different file.
I got the following code to read the original textfile and read it into a different file. How can I change the format?
Original textfile
116
11/2/2012 18:22
N9 45.483 E10 30.495
416 m
117
11/2/2012 18:22
N9 45.483 E10 30.495
415 m
New textfile after changing the format
116,11/2/2012 18:22,N9 45.483 E10 30.495,416 m
117,11/2/2012 18:22,N9 45.483 E10 30.495,415 m
Source code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
namespace Reading_textfile
{
class Program
{
static void Main(string[] args)
{
string filePath = @"C:\Users\ryuma\Downloads\Elephantread.txt";
//string[] Lines = File.ReadAllLines(filePath);
List<string> lines = new List<string>();
lines = File.ReadAllLines(filePath).ToList();
foreach (String line in lines)
{
Console.WriteLine(line);
}
string filePath2 = @"C:\Users\ryuma\OneDrive\Desktop\WriteFile.txt";
File.WriteAllLines(filePath2, lines);
Console.ReadLine();
}
}
}