So simple yet so stuck – Stream Read/Write issue

Hello all,

I am having an issue with my Stream writer / reader and for some reason just cannot wrap my head around a solid solution.

The issue:

I want to write a multiline textbox address on a single line in a text file


1234 Test St. Beverly Hills, CA 90210 

on the text file = 1234 Test St. Beverly Hills, CA 90210

I got this part working. The issue is when I read it to populate the multiline text box I can't seem to make it re-appear as a multiline. I finally got this to semi work by writing the line with an asterix where I wanted the line to break and then when reading it I use the following code:

write.WriteLine("custStreetAddress:" + txtAddress.Text.Replace(Environment.NewLine, @"*")); 

This will write the line as expected but when I read it I am using

if (output.Contains("custStreetAddress")) { string newText = output.Split(':').Last(); string[] finalText = newText.Split('*'); foreach (string word in finalText) { txtAddress.Text += "\r\n" + word; } } 

Because of the \r\n + word code it will put a new line above the address everytime the customer is updated (which happens a lot in my program) but without it the address will not break the address up.

Any help would be appreciated.

by Pandemonium1x via /r/csharp

Leave a Reply