我想在字符串中使用字符串操作,而不是将字符串带入richTextBox。我的程序目前在richTextBox中进行字符串操作。如何在不使用richTextBox的情况下执行相同的操作?
我遇到的问题是当在richTextBox中更改某些内容时会触发操作。因此,当某些内容发生变化时,程序将扫描富文本框中的html标签并简单地删除所有这些内容。如果不使用richTextBox,怎么能这样做,大概更快?
private void richTextBox1_TextChanged(object sender, EventArgs e)
{
int token = -1;
int token2 = -1;
foreach (string line in richTextBox1.Lines)
{
if (line.Contains("<") || line.Contains(">"))
{
while (richTextBox1.Text.IndexOf("<") > -1 && richTextBox1.Text.IndexOf(">") > -1)
{
token = richTextBox1.Text.IndexOf("<");
token2 = richTextBox1.Text.IndexOf(">", token) + 1;
string clip = richTextBox1.Text.Substring(token, token2 - token);
richTextBox1.Select(token, token2 - token);
if (richTextBox1.SelectedText.Length > 0)
{
richTextBox1.Text = richTextBox1.Text.Replace(richTextBox1.Text.Substring(richTextBox1.SelectionStart, richTextBox1.SelectionLength), " ");
}
richTextBox1.AppendText(" ");
}
}
}
}
答案 0 :(得分:0)
i think you can write function to check text entered in richtext box and call when required.
private void richTextBox1_TextChanged(object sender, EventArgs e)
{
if(your condition)
{
CheckRichTextEntered(richTextBox1.Text)
}
}
public void CheckRichTextEntered(string RichBoxText)
{
int token = -1;
int token2 = -1;
foreach (string line in richTextBox1.Lines)
{
if (line.Contains("<") || line.Contains(">"))
{
while (richTextBox1.Text.IndexOf("<") > -1 && richTextBox1.Text.IndexOf(">") > -1)
{
token = richTextBox1.Text.IndexOf("<");
token2 = richTextBox1.Text.IndexOf(">", token) + 1;
string clip = richTextBox1.Text.Substring(token, token2 - token);
richTextBox1.Select(token, token2 - token);
if (richTextBox1.SelectedText.Length > 0)
{
richTextBox1.Text = richTextBox1.Text.Replace(richTextBox1.Text.Substring(richTextBox1.SelectionStart, richTextBox1.SelectionLength), " ");
}
richTextBox1.AppendText(" ");
}
}
}
}