Click here to Skip to main content
15,899,754 members
Please Sign up or sign in to vote.
1.44/5 (2 votes)
See more:
Hello All,

I am copying stringbuilder data to a text box.

for example i have a stringbuilder

C#
stringbuilder sb=new stringbuilder();

sb.appendline("hello how are you")

sb.appendline("hello how are you")

sb.appendline("hello how are you")

sb.Replace("r\n","<br>")

now I am copying it to textbox

textbox.Text=sb.toString();

but on output it inserted <br> tag in textbox text gives result

I need output as
hello how are you<br />
hello how are you<br />
hello how are you


This is working fine if I set to a div like div.innerHtml=sb.tostring();

BUT I need to do that in textbox

Thanks
Posted
Updated 12-Apr-13 13:00pm
v5
Comments
Maciej Los 12-Apr-13 17:45pm    
WebControls, WinForms?
joshrduncan2012 12-Apr-13 17:50pm    
Need to insert newlines?
lewax00 12-Apr-13 18:25pm    
Are you sure the text box is set to allow multiple lines? And what happens if you don't do the replacement?
PIEBALDconsult 12-Apr-13 19:01pm    
"it inserted <br> tag in textbox"

Of course, you told it to. Try it without the Replace.

1 solution

Why you are replacing the line terminator with
. Text box understands the line terminator perfrectly..

The following code works fine..


C#
sb.AppendLine("hello how are you");

            sb.AppendLine("hello how are you");

            sb.AppendLine("hello how are you");


            textBox1.Text = sb.ToString();



is there any reason to use BR Tag? if you want to use HTML tags you need to use a rich text box not the ordinary text Box...

cheers..
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900