How can I put text from a multi-line text box into one string?
Posted
by Kevin van Zanten
on Stack Overflow
See other posts from Stack Overflow
or by Kevin van Zanten
Published on 2010-06-17T10:50:40Z
Indexed on
2010/06/17
10:53 UTC
Read the original article
Hit count: 295
Dear reader,
I'm faced with a bit of an issue. The scenario is that I have a multi-line text box and I want to put all that text into one single string, without any new lines in it. This is what I have at the moment:
string[] values = tbxValueList.Text.Split('\n');
foreach (string value in values)
{
if (value != "" && value != " " && value != null && value != "|")
{
valueList += value;
}
}
The problem is that no matter what I try and what I do, there is always a new line (at least I think?) in my string, so instead of getting:
"valuevaluevalue"
I get:
"value
value
value".
I've even tried to replace with string.Replace
and regex.Replace
, but alas to no avail. Please advise.
Yours sincerely,
Kevin van Zanten
© Stack Overflow or respective owner