Hi @Mansour_Dalir ,
You can refer to the following code.
Use dictionary key-value pairs to implement categorical storage data.
Dim dt As New DataTable
dt.Columns.Add("a")
dt.Columns.Add("b")
dt.Rows.Add("a1", "1")
dt.Rows.Add("a1", "2")
dt.Rows.Add("a2", "3")
dt.Rows.Add("a2", "4")
dt.Rows.Add("a3", "5")
dt.Rows.Add("a3", "6")
Dim dict As New Dictionary(Of String, List(Of String))()
Dim array1 As New List(Of String)()
Dim array2 As New List(Of String)()
For i As Integer = 0 To dt.Rows.Count - 1
Dim key As String = dt.Rows(i)("a").ToString()
Dim value As String = dt.Rows(i)("b").ToString()
If dict.ContainsKey(key) Then
dict(key).Add(value)
Else
dict(key) = New List(Of String) From {value}
array1.Add(key)
End If
Next
For Each pair As KeyValuePair(Of String, List(Of String)) In dict
array2.Add(String.Join("-", pair.Value))
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.