Question Singing the Environment.NewLine to <br /> blues

gchq

Well-known member
Joined
Dec 14, 2007
Messages
168
Programming Experience
10+
In the past a text string saved to a DB and later retrieved to say, a div control, using .InnerHTML has preserved line breaks by using String.Replace(Environment.NewLine, "<br />")..

For some reason that is no longer working. Have I missed some changes, or is it just Friday afternoon?

Thanks

.NET 4.0 | IE 9.0 | VS2010
 
I can't see your code so i am going to guess that you are doing something wrong there.
To solve this you can use one of the two methods available:

Dim anexample As String = "blah blah" & Environment.NewLine

Dim tobesaved1 As String = anexample.Replace(Environment.NewLine, "< br / >")
' Or this one (VisualBasic namespace)
Dim tobesaved2 As String = Replace(anexample, Environment.NewLine, "< br / >")
 
After going through a s**t load of combinations, this worked

ControlChars.Lf

I was always under the impression it was only the RichTextBox that used that format! Go figure...

Have a great weekend. Thank you for taking the time to reply
 
Back
Top