I have txt file(65mb)i need to read line by line and change each line, For example i have many lines
User=value Password=value Phone=123456789
User=value Password=value Phone=123456789
User=value Password=value Phone=123456789
and i need to change first number of credit card/Phone to*(security reason), and get text like this and save it, or just to change origin text file.
User=value Password=value Phone=*****6789
User=value Password=value Phone=*****6789
User=value Password=value Phone=*****6789
I build new string and add to there line(changed) by line than save, but it take me to many time this is my code
string NewPath = "";
string lineOfText;
string NewTextFile = "";
using (var filestream = new FileStream(FilePath,
FileMode.Open,
FileAccess.Read,
FileShare.ReadWrite))
{
var file = new StreamReader(filestream, Encoding.UTF8, true, 128);
while ((lineOfText = file.ReadLine()) != null)//here i reading line by line
{
NewTextFile += lineOfText.Substring(0, 124) + "************" +
lineOfText.Substring(136, lineOfText.Length - 136);
NewTextFile += Environment.NewLine;//here i make new string
}
}
NewPath = FilePatharr[1] + "\\temp.txt";
System.IO.File.WriteAllText(NewPath, NewTextFile);//here i save him
Do any one know better way to do this,my code is taking to long to save this big file.
UPDATE
Why do i get -2 for this question? Whats wrong with this question? I see here only wrong answers about how to pass sensitive data and more things that not belong to this questions When the question was -->Fast way to change txt file and save it
Any way i find out how to do this speed of saving file speedUp from 100kb\sec to 3MB\sec now it taking me 20sec and not 20min like before