- May 7, 2013
- 10,400
Evening everyone,
I'm attempted to make a simple parser which takes a string in BBCode format, removes the tags and then makes the text bold using the RichTextBox functionality. The text is made bold, however, a non-bold string is produced first and then the bold string.
I believe the issue may lie with the fact that the Text property of the RichTextBox control is being populated first, and then a new string is being altered?
I'm attempted to make a simple parser which takes a string in BBCode format, removes the tags and then makes the text bold using the RichTextBox functionality. The text is made bold, however, a non-bold string is produced first and then the bold string.
Code:
private void parseButton_Click(object sender, EventArgs e)
{
foreach(String line in richTextBox1.Lines)
{
String[] subStrings = line.Split('-');
foreach(String subString in subStrings)
{
if ((subString.StartsWith("['b]") && subString.EndsWith("['/b]")))
{
String noStartTag = "";
String noEndTag = "";
noStartTag = subString.Replace("['b]", "")[B];
[/B]noEndTag = noStartTag.Replace("[/'b]", "");
richTextBox2.SelectedText = noEndTag;
richTextBox2.SelectionFont = new Font(richTextBox2.Font, FontStyle.Bold);
}
}
I believe the issue may lie with the fact that the Text property of the RichTextBox control is being populated first, and then a new string is being altered?