[英]How can I remove from richtextbox only the text that's Strikeout?
您好,我对Richtextbox有一点问题,我尝试仅删除Strikeout单词,但是如果我有一个显示为Regular字体的单词,那么该单词也将被删除。 如何仅删除Strikeout中的单词?
这是我的代码:
text = richTextBox2.Text;
string[] destLine = richTextBox2.Text.Split(WordSeparaterss);
foreach (string str in destLine)
{
int startIndex = 0;
while (startIndex != -1)
{
startIndex = richTextBox2.Find(str, startIndex + 1,
richTextBox2.Text.Length,
RichTextBoxFinds.WholeWord);
if (startIndex != -1)
{
richTextBox2.Select(startIndex, str.Length);
if (richTextBox2.SelectionFont.Strikeout)
{
text = text.Replace(str, string.Empty);
}
}
}
}
例如,这是文本,我在“ * ”之间删除了文本
***Deutschlektionen erlauben vertiefende Einblicke für den Aufbau der deutschen Sprache. Satzbau, Präpositionen, Pronomen und viele andere Themen werden kompakt präsentiert und mit einem berühmten Zitat veranschaulicht. Deutschkurs - Grammatik***
Gramatik und viele zum.
这就是我从代码中得到的:
ane wer Gramatik zum.
我只想得到: Gramatik und viele zum.
此方法检查当前文本的长度。 然后从头开始逐字符检查。 如果样式是Strikeout
,则将其删除。 请注意,计数从结尾开始。 这是因为删除一个字母或索引后会减少。 如果从头算起,索引的更改将仅影响已调查的文本。
this.richTextBox1.SelectAll();
int textLength = this.richTextBox1.SelectedText.Length;
for (int i = textLength; i >= 0; --i)
{
this.richTextBox1.Select(i, 1);
if (this.richTextBox1.SelectionFont.Style == FontStyle.Strikeout)
{
this.richTextBox1.SelectedText = string.Empty;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.