Michael,
I agree with your coding, but my requirement is slightly
diffrent. I have a multiline text box placed in the
form, Into this text box I am reading reading three
fields as follow :
txtbox.text = field1 & crlf field2 & crlf field3
This will show the result in the multiline text box one
after the other as follows.
result1
result2
result3
The user can change the values in the text box, if he/she
changes the values, how do I write back to the file
these values that appear one after the other to the three
fields in the file I mentioned above?
Hope you got what I am trying to do?
Suresh
So do you have 3 variables in your application that you want to write to
a file, or do want to write the contents of the textbox!? It doesn't
matter where the data in the textbox comes from. If you want a text
file written as the text appears in the textbox, then use the code I've
shown.
Are you saying you want to parse the data in the textbox into three
variables in your application. That would be another question entirely.
I'm guessing that you have:
1) read a text file one line at a time using "sw.ReadLine()"
2) saved each line into a separate variable
3) wrote each variable in turn to the text box.
Is this the case? if so why not just do "sw.ReadToEnd()" into a single
string variable, and then put it directly into the textbox? Is there
another reason you need each line in a separate variable? If so then,
as Rick said, you should not let the user edit them all via a single
text box.
You can write a series of variables out to a flat text file with each on
a separate line. It certainly isn't how I would design a settings file,
but you can do it. The StreamWriter also has a WriteLine(...) method to
write a single string to a line followed by a newline character.
You should really take a look at the help files on StreamWriter.