I am trying to design an app that strikes out certain characters on a string if another 1 or 2 strings are contained within that string.
So far I can seem to get the leading sub string to do its thing fairly reliably, but the second sub-string always seems to produce unpredictable results, can anyone help? (c# or vb is fine)
A screen snip example of it working for the main (1st) filter, but not the sub (2nd):
Heres the code:
Public Function FormatFilteredName(mainFilter As String, subFilter As String) As TextBlock
Dim tbNew As New TextBlock(New Run(FullFileName))
tbNew.Text = FullFileName
tbNew.FontSize = FONT_SIZE
If Not String.IsNullOrEmpty(FullFileName) Then
If Not String.IsNullOrEmpty(mainFilter) Then
GetFilterSpan(mainFilter, tbNew)
End If
If Not String.IsNullOrEmpty(subFilter) Then
GetFilterSpan(subFilter, tbNew)
End If
End If
Return tbNew
Private Function GetFilterSpan(filter As String, ByVal tbNew As TextBlock) As Span
Dim offset As Integer = tbNew.Text.ToLower().IndexOf(filter.ToLower()) + 1
Try
If offset > -1 Then
Dim tpStart As TextPointer
tpStart = tbNew.ContentStart.GetPositionAtOffset(offset)
Dim tpEnd As TextPointer
tpEnd = tbNew.ContentStart.GetPositionAtOffset(offset + filter.Length)
If Not tpStart Is Nothing And Not tpEnd Is Nothing Then
Dim result As New Span(tpStart, tpEnd)
result = ApplySpanStrikeOutStyle(result)
Return result
End If
End If
Catch ex As Exception
Return Nothing
End Try