Hi @Mansour_Dalir ,
Please check if the following code helps.
I treated End as a separate markup element, removing it from the RemoveList.
Dim results As List(Of String) = sttMain.Select(Function(line)
Dim elements As String() = line.Split("|"c)
Dim result As New StringBuilder()
Dim ABelement As Boolean = False
Dim keepAdding As Boolean = True
For Each element As String In elements
If Not RemoveList.Contains(element) Then
If element = "A_Get:" Then
result.Append("|")
result.Append(element)
ABelement = True
ElseIf element = "B_Get:" Then
If result(result.Length - 1) = ":" Then
result.Append("null")
End If
result.Append("|")
result.Append(element)
ABelement = True
ElseIf element = "End" Then
If result(result.Length - 1) = ":" Then
result.Append("null")
End If
ABelement = False
ElseIf element = "Limit End" Then
keepAdding = False
Exit For ' Ignore the rest of the elements starting from "Limit End"
Else
If ABelement Then
result.Append(",")
result.Append(element)
Else
If result.Length > 0 Then
result.Append("|")
End If
result.Append(element)
End If
End If
End If
Next
result.Replace(":,", ":")
Return result.ToString()
End Function).ToList()
For Each result In results
Console.WriteLine(result)
Next
Best Regards.
Jiachen Li
If the answer is helpful, please click "Accept Answer" and upvote it.
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.