如何在不干扰标记的情况下从流文档段落中删除字符串
本文关键字:文档 段落中 字符串 删除 情况下 干扰 | 更新日期: 2023-09-27 18:33:35
作为RichTextBox的新手和谷歌搜索了几个小时,我被难住了。隔离了流文档的段落部分。我现在希望删除该段落中第一个":"之前的所有文本,但保留该段落的其余部分(包括其所有格式 --XAML)。(这在 WPF 与 2010 中)。
我确定它很简单,但这是怎么做到的?
到目前为止,我所拥有的将读到第一个":",但是您如何删除此文本?有没有更好的方法??
public InkRichViewModel(int p, Paragraph paragraph)
{
this.p = p;
//Read the paragraph title from the paragraph
TextPointer start = paragraph.ContentStart;
TextPointer end = FindWordFromPosition(start, ":");
TextRange textRange = new TextRange(start, end);
String Title = textRange.Text;
//Remove the title from the paragraph
TextPointer endp = paragraph.ContentEnd;
TextRange t2 = new TextRange(start, endp);
?????????????????????????????????????????
this.Note = paragraph; <---Note is the paragraph without the leading string.
}
感谢所有的帮助,问候。
就我而言,这解决了上述问题。有没有更好的方法?
// Read paragraph upto and including first ":"
string text = (paragraph.Inlines.FirstInline as Run).Text;
int r = text.IndexOf(":")+1;
string Title = text.Substring(0,r).Trim();
// Remove Title from text;
string newtext = text.Substring(r).Trim();
// Insert new inline and remove the old inline.
Inline z = paragraph.Inlines.FirstInline;
Run runx = new Run(newtext);
paragraph.Inlines.InsertBefore(z, runx);
paragraph.Inlines.Remove(z);
this.Note = paragraph;