I have this particular problem where file.WriteAllText
adds an extra white space at the end of the file.
Im using an Ubuntu OS and have monodevelop installed for my C# coding. Im trying to concatenate two files together i.e file1.txt and file2.txt together. But when I do i see an white space at the end of the file. My code is as below
using System.IO;
namespace WebApplication1
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string file1 = File.ReadAllText(@"/home/usr/test/file1.txt");
string file2 = File.ReadAllText(@"/home/usr/test/file2.txt");
File.WriteAllText(@"/home/usr/test/result.txt", file1.Trim()+file2.Trim());
}
}
}
Ideally usage of Trim()
function should remove extra spaces at start/end of the string. But when I open my file in edit mode, I see an extra space at the end of the file result.txt. How can I get rid of it or why is it performing this way?