Я хочу получить символ / слово после моего ключевого слова.В моем коде у меня есть ключевое слово = функция.Когда пользователь пишет в richtextbox «function a», мне нужно получить «a», и я не могу установить подобную функцию, потому что она будет вставлена пользователем.Мой код выглядит так:
string keyword = "function";
string newString = randomString;
TextRange text = new TextRange(_richTextBox.Document.ContentStart, _richTextBox.Document.ContentEnd);
TextPointer current = text.Start.GetInsertionPosition(LogicalDirection.Forward);
while (current != null)
{
string textInRun = current.GetTextInRun(LogicalDirection.Forward);
if (!string.IsNullOrWhiteSpace(textInRun))
{
int index = textInRun.IndexOf(keyword);
if (index != -1)
{
TextPointer selectionStart = current.GetPositionAtOffset(index, LogicalDirection.Forward);
TextPointer selectionEnd = selectionStart.GetPositionAtOffset(keyword.Length, LogicalDirection.Forward);
TextRange selection = new TextRange(selectionStart, selectionEnd);
selection.Text = newString;
selection.ApplyPropertyValue(TextElement.FontWeightProperty, FontWeights.Bold);
_richTextBox.Selection.Select(selection.Start, selection.End);
_richTextBox.Focus();
}
}
current = current.GetNextContextPosition(LogicalDirection.Forward);