Hi @Mansour_Dalir ,
Please check if the following code helps.
Dim sttDataToArray As String = "-1,-1,-78,56,23,-1,-66789,23,-1,-1"
Dim MyArrayBinary As String() = Split(sttDataToArray, ",")
Dim resultArray As Integer() = MyArrayBinary.Select(Function(x) If(Integer.TryParse(x, Nothing), If(Convert.ToInt32(x) = -1, 0, 1), 0)).ToArray()
Dim finalResult As String() = resultArray.Select(Function(x) x.ToString()).ToArray()
Dim countArray As New List(Of String)()
Dim numberArray As New List(Of Integer)()
Dim currentNumber As Integer = resultArray(0)
Dim currentCount As Integer = 1
For i As Integer = 1 To resultArray.Length - 1
If resultArray(i) = currentNumber Then
currentCount += 1
Else
countArray.Add($"{currentNumber}={currentCount}")
numberArray.Add(currentCount)
currentNumber = resultArray(i)
currentCount = 1
End If
Next
countArray.Add($"{currentNumber}={currentCount}")
numberArray.Add(currentCount)
Dim resultString As String = String.Join(",", finalResult)
Dim countResult As String = String.Join(",", countArray)
Dim numberResult As String = String.Join(",", numberArray)
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.