Wednesday, November 21, 2007

How to show line breaks in an asp.net label.

When data is collected via a TextBox and line breaks are provided in the input, this is a way to show those breaks in a label. This was surprisingly difficult to figure out for me, so hopefully this will save someone some time.

public string WrappableText(string source)
{
string nwln = Environment.NewLine;
return "

" +
source.Replace(nwln + nwln, "

")
.Replace(nwln, "
") + "

";
}

0 comments: