Skip to content

Instantly share code, notes, and snippets.

@igorkulman
Created October 17, 2015 12:43
Show Gist options
  • Save igorkulman/87b051f2f3a54bf895f0 to your computer and use it in GitHub Desktop.
Save igorkulman/87b051f2f3a54bf895f0 to your computer and use it in GitHub Desktop.
private void Update()
{
if (string.IsNullOrEmpty(Text) || string.IsNullOrEmpty(HighlightedText))
{
TB.Inlines.Clear();
return;
}
TB.Inlines.Clear();
var parts = Regex.Split(Text, HighlightedText, RegexOptions.IgnoreCase);
var len = 0;
foreach (var part in parts)
{
len = len + part.Length + 1;
TB.Inlines.Add(new Run
{
Text = part
});
if (Text.Length >= len)
{
var highlight = Text.Substring(len - 1, HighlightedText.Length); //to match the case
TB.Inlines.Add(new Run
{
Text = highlight,
Foreground = HighlightBrush
});
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment