Is there a way to keep formatting when outputting to a shortcut?

I have user input that I output to the label.

I used HTML.Encode to show input in how the user entered it (ignoring it as an html tag).

However, I noticed that user input, such as New Line, is not used in the label. It just displays as a space.

I did it

                msg.Text = msg.Text.Replace(Environment.NewLine, "<br />");

which now displays the correct input.

Is this the best way to do this? Or exists as a regular method that can convert newLines, tabs, etc. Any invisible formatting in HTML tags?

+3
source share
2 answers

. , ( , "\n" "\ r\n" ), "\ r\n", "\n" .

lbl.Text = lbl.Text.Replace("\r\n", "<br />").Replace("\n", "<br />");

4 .:

lbl.Text = lbl.Text.Replace("\t", "&nbsp;&nbsp;&nbsp;&nbsp;")

( html ), :

lbl.Text = lbl.Text.Replace("  ", "&nbsp;&nbsp;")//Replace every 2-space pair.

< br/ > .

TextBox, MultiLine "true" "Enabled" "false", , . , - , .

+3

If possible, just use a multi-line text box instead of a label.

0
source

All Articles