Hi @Mansour_Dalir ,
You can try creating a separate array of record positions, and record the position of the result after each split.
Here is an example.
Function MultiFinderStringPositions(BodyText As String, MultiFind As List(Of String)) As String()
Dim result1 As String() = {BodyText}
Dim result2 As String() = {}
Dim result3 As String() = {}
Dim startindex As Integer = 0
Dim positions1 As Integer() = {}
Dim positions2 As Integer() = {}
For Each item In MultiFind
Dim idx As Integer = MultiFind.IndexOf(item)
If idx = MultiFind.Count - 1 Then
For i = 0 To result1.Length - 1
Dim res As String() = result1(i).Split(item)
result2 = result2.Concat(res).ToArray
For Each str As String In res
positions2 = positions2.Append(result1(i).IndexOf(str, startindex) + positions1(i)).ToArray
startindex = result1(i).IndexOf(str, startindex) + str.Length - 1
Next
startindex = 0
Next
Else
For i = 0 To result1.Length - 1
Dim res As String() = result1(i).Split(item).Where(Function(f) f Like "*" & MultiFind(idx + 1) & "*").Select(Function(f) f).ToArray
result2 = result2.Concat(res).ToArray
For Each str As String In res
If idx = 0 Then
positions2 = positions2.Append(BodyText.IndexOf(str, startindex)).ToArray
startindex = BodyText.IndexOf(str, startindex) + str.Length - 1
Else
positions2 = positions2.Append(result1(i).IndexOf(str, startindex) + positions1(i)).ToArray
startindex = result1(i).IndexOf(str, startindex) + str.Length - 1
End If
Next
startindex = 0
Next
startindex = 0
result1 = result2
result2 = {}
positions1 = positions2
positions2 = {}
End If
Next
For i = 0 To result2.Length - 1
result3 = result3.Append((positions2(i) & "-" & (positions2(i)) + result2(i).Length - 1).ToString).ToArray
Next
Return result3
End Function
Best Regards.
Jiachen Li
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.