I'm trying to remove text from a specific line in the file that i have created "Test.txt".
Here is the text written in Test.txt:
1
2
3
4
5
6
7
8
9
10
Now what i want to happen is when i'm going to remove 1-5, the numbers 6 - 10 should replace the line for 1-5. Like this:
6
7
8
9
10
But when i tried the code it gave me this output:
6
7
8
9
10
As you can see the above output, that is the unwanted space that i'm talking about.
What I have tried:
Here is the code that I have tried:
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TestCode
{
class Program2
{
static void Main()
{
lineChanger("", @"C:\Users\User1\Documents\Visual Studio 2015\WebSites\MusicStore\Pages\Test.txt", 1);
lineChanger("", @"C:\Users\User1\Documents\Visual Studio 2015\WebSites\MusicStore\Pages\Test.txt", 2);
lineChanger("", @"C:\Users\User1\Documents\Visual Studio 2015\WebSites\MusicStore\Pages\Test.txt", 3);
lineChanger("", @"C:\Users\User1\Documents\Visual Studio 2015\WebSites\MusicStore\Pages\Test.txt", 4);
lineChanger("", @"C:\Users\User1\Documents\Visual Studio 2015\WebSites\MusicStore\Pages\Test.txt", 5);
}
static void lineChanger(string newText, string fileName, int line_to_edit)
{
string[] arrLine = File.ReadAllLines(fileName);
arrLine[line_to_edit - 1] = newText;
File.WriteAllLines(fileName, arrLine);
}
}
}
Also please feel free to suggest any proper techniques and kindly include actual examples.