✅ How do i move to the next line on a text file and output both lines?
The first image prints the same line twice onto a text file which is expected
For the second image, the console.readline() should move to the next line and print that out after the first but it doesnt, it doesnt print anything
help please!
14 Replies
You mean the second line should print what is being read through ReadLine()?
yeah
so on the first image, it outputs the first line on the text file twice
i want it to, on the second image, output the first line of the text file and then the next line
In that case, Console.ReadLine() returns the line it read, so you need to actually assign it to a string you want to print
but its not doing that on the second image ;-;
how?
var readString = Console.ReadLine();
Console.WriteLine(readString);
You can also reassign one of the variables you print
But from your screenshot I can't tell which is supposed to be what
my code is way too long and complexed, ill try this out
you don't mean you're trying to read from the same file you're writing to do you?
its from the same file
the file has more than one line
i want to output the lines seperately
i dont understand this
how do i assign it to a string i want to read
trying to read from and write to the same file simultaneously will probably be painful - if you can do all your writing first and the read it (or vice versa) that'll be a lot easier, depends what you're trying to achieve really
is the string the file contnets
oh wait no, im reading from one file and then writing to another
Console.ReadLine()
reads what the user types into the Console, not from a filebut i need to read seperate lines in one file to write the seperate lines on the other file
is there a reason you need to specifically read one line, write one line before moving on?
in the overall code im trying to make, the file has seperate lines with number values and other data. im trying to get these values and print it onto another file order from highest to lowest
so i need them seperately as each line is different values
an all nighter trying to do something as simple as just reading and outputting the next line it is!