Search code examples
c#filetextnewlinestore

Insert new Line while storing text file using c#


I got two string Latitude and longitude of a place from code. I am using c#.I want to store it with a new line order. Like I want to save latitude and longitude

Lat: 94.000
Lon: 54.1010

I have tried this code in this way. But it is not working at all

Lat_text.Text = Latitude.ToString();
Lon_Text.Text = Longitude.ToString();
File.WriteAllText(path,"Lat:" +Lat_text.Text +"\n"+"Lon:"+ Lon_Text.Text);

Solution

  • \n for Unix platforms. Use \r\n instead. Or better use Environment.NewLine instead.

    File.WriteAllText(path, "Lat:" + Lat_text.Text + Environment.NewLine + "Lon:" + Lon_Text.Text);