Thursday, March 22, 2012

Newline Characters

I added a newline to a string using: ControlChars.NewLine

I want to convert all those newlines to "<br>"

i tried:


Replace(myString, cStr(ControlChars.NewLine) , "<br>")

but it had no effect at all. any ideas?I think it is the other way around:


Replace(myString, "<br>", cStr(ControlChars.NewLine))

If you're using VB, don't you have access to the vbCrLf constant? If so you might be able to do

Replace(myString, vbCrLf, "<br>")

or

Replace(myString, Chr(13), "<br>")
Hello,

i always replace my newline with the help ofRegular Expression code like in the following example...

// Remove the newline's and replace them with <br /> tag
Regex inRegex;
inRegex = new Regex("\n", RegexOptions.IgnoreCase);
lblTest.Text = inRegex.Replace(sText, "<br />");
This sample is written in C# but it should be easy to translate to vb.net. If you need further help please post again...

HTH,
thanks guys,

it worked! btw, what does vbcrlf stand for?
vbcrlf --> I believe it is "VisualBasic CarriageReturn and Line Feed"
Or you can use Environment.NewLine no matter what language you are using.

0 comments:

Post a Comment