how to convert a multiline textbox to a single line string?

G

garyusenet

I have a multi line text box, i'd like to store the contents of this
textbox to a text file. However when I write the value of '
textbox.text ' to the file it is written verbatim spanning many lines
if enter has been pressed.

I'd like to store the value of the textbox on one single line in the
file. How do i do this?

I assume i'll need to read new line characters from the textbox.text
string, and replace them with some token ?

Is this how I'd do it, and if so can you suggest some sample code?

Thanks,

Gary.
 
B

Bobbo

I assume i'll need to read new line characters from the textbox.text
string, and replace them with some token ?

The easiest way I can see of doing that for this particular exercise,
is applying the .Replace() method to the string value of the textbox.

e.g.
string textBoxValue = textBox1.Text.Replace(Environment.NewLine,
"TOKEN");

Where TOKEN is the token you're using to represent it in the single
line, and Environment.NewLine is a constant representing whatever a
newline is in the current environment, as different platforms have
different ways of representing this.
 
G

garyusenet

Such an elegent solution. This is exactly what I needed.

Thankyou Bobbo.

Gary.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top