badb0nny
✅ Probably a simple general knowledge question, not to sure what to title it?
Im trying to store some data in a seperate file and then use it in a string but for some reason the string seems to come out as 2 strings which split at the variable?
for some reason returns
hello
/data/
and im trying to make it return
hello /data/
2 replies
❔ Reading data from a text file
I have only just started trying to work with txt files and was wondering if anyone could help me and try to fix my code!
string fileName = "Cookies.txt";
TextWriter textFileWrite = new StreamWriter(fileName);
TextReader textFileRead = new StreamReader(fileName);
string data;
if ((data = textFileRead.ReadLine().Skip(1).Take(1).First().ToString()) == null)
{
Console.WriteLine("Would you like to save 'dark' or 'light' theme..."); string choice = Console.ReadLine();
textFileWrite.WriteLine(choice);
}
if ((data = textFileRead.ReadLine().Skip(1).Take(1).First().ToString()) != null)
{
Console.WriteLine("You selected: " + data);
Console.WriteLine("Would you like to save 'dark' or 'light' theme..."); string choice = Console.ReadLine();
textFileWrite.WriteLine(choice);
}
textFileRead.Close();
textFileWrite.Close();
11 replies