I would like to insert the following into a string
some text here
some text here
some text here
If you want to remove spaces at the beginning/end of a line too(common when shortening html) you can try:
string.Join("",input.Split('\n','\r').Select(s=>s.Trim()))
Else use the simple Replace
Marc suggested.
How about using a Regex?
var result = Regex.Replace(input, "\r\n", String.Empty)
If you just want to remove the new line at the very end use this
var result = Regex.Replace(input, "\r\n$", String.Empty)
How about:
string s = orig.Replace("\n","").Replace("\r","");
which should handle the common line-endings.
Alternatively, if you have that string hard-coded or are assembling it at runtime - just don't add the newlines in the first place.