Reputation: 264
I have a C# foreach loop with the following:
lblCheckedNodes.Text += node.Text + "►< br />";
That displays like this: myCheckedNodeText►< br /> . Which shows the line break characters instead of actually doing the line break, but if I do:
lblCheckedNodes.Text += node.Text + "<br />";
the line return works, but i can't seem to get both working.
Upvotes: 0
Views: 50
Reputation: 76607
Missing Semicolon in HTML Entity
HTML entities like ►
require a trailing semicolon to indicate the end of the entity itself, so you need to ensure that is present:
lblCheckedNodes.Text += node.Text + "►<br />";
Consider a StringBuilder
As mentioned in the comments, if you are continually concatenating strings together, you may be better off using the StringBuilder
class, which is far more efficient at handling that type of activity:
StringBuilder nodes = new StringBuilder("");
// Build your strings here
foreach (var node in nodes)
{
// You have a few options for concatenation here
// Basic Concatenation -> nodes.Append(node.Text + " ► <br />");
// String.Format() -> nodes.Append(String.Format("{0} ► <br />", node.Text));
// String Iterpolation (seen below)
nodes.Append($"{node.Text} ► <br />");
}
// Set your label content
lblCheckedNodes.Text = nodes.ToString();
Upvotes: 3
Reputation: 501
I think you are just missing a semicolon. Try this
lblCheckedNodes.Text += node.Text + "►<br />";
Upvotes: 1