0

I have a multiline textbox in my C# web form. I am trying to output the contents of that textbox to HTML. However, when I type the below in the textbox

Line 1
Line 2
Line 3

I get this output in my HTML.

Line 1 Line 2 Line 3

Is there anyway to keep the same formatting from textbox to HTML?

maltman
  • 454
  • 1
  • 7
  • 28
  • Did you try replacing `\n` with `
    `?
    – Namoshek Oct 25 '17 at 16:59
  • So I created a variable string textbox = textbox1.text and am passing that to the HTML. How would I pass a break to that variable? – maltman Oct 25 '17 at 17:10
  • Did you read Namoshek's comment? – mason Oct 25 '17 at 17:12
  • yes. so do I just do something like string variable = textbox.replace("\r\n", "
    )?
    – maltman Oct 25 '17 at 17:15
  • OK that worked. Thanks guys. – maltman Oct 25 '17 at 17:20
  • I wrote the code by the time this was closed, so here goes. var textBoxLines = $"Line 1{Environment.NewLine}" + $"Line 2{Environment.NewLine}" + $"Line 3{Environment.NewLine}"; var htmlText = string.Empty; var linesOfText = textBoxLines.Split(new[] { Environment.NewLine }, StringSplitOptions.None); foreach (var lineOfText in linesOfText) { htmlText += lineOfText + "
    "; }
    – AzzamAziz Oct 25 '17 at 17:22

0 Answers0