I need to read accounts.txt and add/change number after password
Here is accounts.txt
user|password
user1|password1
After starting
user|password|1
user1|password1|1
After closing
user|password|0
user1|password1|0
Sorry for my english
I need to read accounts.txt and add/change number after password
Here is accounts.txt
user|password
user1|password1
After starting
user|password|1
user1|password1|1
After closing
user|password|0
user1|password1|0
Sorry for my english
Add this reference first System.IO
Then:
For reading:
string[] accounts= File.ReadAllLines("accounts.txt");
//each item of array will be your account
For modifying :
accounts[0] += "|1";//this adds "|1" near password
accounts[0].Replace("|1","|0"); this will change the "|0" text to "|1"
And For writing:
File.WriteAllLines("accounts.txt",accounts);
Something like that :
string[] lines = File.ReadAllLines(@"C:\filepath.txt");
List<string> newlines = new List<string>();
foreach(string line in lines)
{
string[] temp = line.Split('|');
newlines.Add(temp[0] + "|" + temp[1] + "|" + "1");
}
File.WriteAllLines(@"C:\filepath.txt", newlines.ToArray())
Look at System.IO.File
class, as well as general System.IO.Stream
and System.IO.StreamReader
classes.
There are a bunch of examples on the internet on how to read and write text files in .NET: http://msdn.microsoft.com/en-us/library/db5x7c0d(v=vs.110).aspx