Here are the steps:

Step 1: Open a blank app and add two TextBlocks and a button either from the toolbox or by copying the following XAML code into your grid.
  1. <StackPanel Margin="10,40,0,0">
  2. <TextBlock Text="Type the word to find" ></TextBlock>
  3. <TextBox Name="textToFind" Width="200" Margin="0,10,0,0" HorizontalAlignment="Left"></TextBox>
  4. <TextBlock Text="Type or Copy and Paste a sentence to find from " Margin="0,10,0,0" ></TextBlock>
  5. <TextBox Name="sentence" Height="100" Width="300" HorizontalAlignment="Left" Margin="0,10,0,0" TextWrapping="Wrap"></TextBox>
  6. <Button Name="find" Content="Find" Height="40" Width="120" Click="find_Click" Margin="0,10,0,0" ></Button>
  7. <TextBlock Name="result" TextWrapping="Wrap" Width="300" HorizontalAlignment="Left"></TextBlock>
  8. </StackPanel>


Step 2:
Add the following namespaces to your project which is needed in further C# code.
  1. using System.Collections.Generic;
  2. using Windows.Data.Text;
  3. using Windows.UI.Text;
  4. using Windows.UI.Xaml.Documents;

Step 3: Copy and paste the following code to the cs page which will be called on button click event and the corresponding text will be highlighted.

  1. private void find_Click(object sender, RoutedEventArgs e)
  2. {
  3. result.Text = "";
  4. var mySemanticTextQuery = new Windows.Data.Text.SemanticTextQuery(textToFind.Text);
  5. IReadOnlyList<Windows.Data.Text.TextSegment> ranges = mySemanticTextQuery.Find(sentence.Text);
  6. HighlightRanges(result, sentence.Text, ranges);
  7. }
  8. public void HighlightRanges(TextBlock tb, String TextContent, IReadOnlyList<TextSegment> ranges)
  9. {
  10. int currentPosition = 0;
  11. foreach (var range in ranges)
  12. {
  13. if (range.StartPosition > currentPosition)
  14. {
  15. int length = (int)range.StartPosition - currentPosition;
  16. var subString = TextContent.Substring(currentPosition, length);
  17. tb.Inlines.Add(new Run() { Text = subString });
  18. currentPosition += length;
  19. }
  20. var boldString = TextContent.Substring((int)range.StartPosition, (int)range.Length);
  21. tb.Inlines.Add(new Run() { Text = boldString, FontWeight = FontWeights.Bold });
  22. currentPosition += (int)range.Length;
  23. }
  24. if (currentPosition < TextContent.Length)
  25. {
  26. var subString = TextContent.Substring(currentPosition);
  27. tb.Inlines.Add(new Run() { Text = subString });
  28. }
  29. tb.Inlines.Add(new Run() { Text = "\r\n" });
  30. }

Step 4: Run your application and test yourself.