Reputation: 22323
My string is Following:
string mystring ="Test1234\r\ntest1234\r\ntest1234\r\ntest dhjfadhdfsfdsjfdf";
It comes from a database and I want to display it in a label as usual format. So, I want to replace \r\n
to <br>
.
I tried using NewString= mystring .Replace('\r\n','<br>');
, but it didn't work.
I got the following error
To many characters in character literal`.If this is not a correct way to do suggest.Thanks.
Upvotes: 0
Views: 90
Reputation: 25619
Thats because you're using '
. you need to use "
.
Anyhow, Label
does not format HTML tags, which means, <br />
will look like <br />
and not like a new line.
for that, you need to use either a span
or a div
or anything similar.
You can replace your Label
with a span
:
<span id="span1" runat="server" />
and then use
span1.Controls.Add(new LiteralControl("your string here with html tags"));
Upvotes: 0
Reputation: 3204
Try this instead, replacing the single quotes with double quotes:
var NewString= mystring.Replace("\r\n","<br>");
Using single quotes indicates that you are going to specify a char instead of a string. You then passed in a string literal consisting of two characters ( the \r and the \n) rather than a single character, causing the error.
Upvotes: 2