想将相同合同号对应的fphm用vbCrLf拼接提取出来,代码该怎么写呢
Dim hth As String
Dim hths() As String = {"QAXSZ230811B/23088", "QAXSZ230811A/23079", "QAXSZ230811A/23079", "QAXSZ230328A/23039", "QAXSZ230328A/23039"}
Dim fphm As String
Dim fphms() As String = {"666", "36357132", "36357333", "36356847", "36356864"}
Array.Sort(HTHs, fphms)
For j As Integer = 0 To HTHs.Length - 1
Dim count As Integer = 0
For k As Integer = j + 1 To HTHs.Length - 1
If(hths(j) = hths(k)) Then
count = count + 1
Else
fphm = fphm & "_" & fphms(j)
End If
Next
If(count = 1) Then
Output.Show("重复hth:" & HTHs(j))
count = 0 '重置
End If
Next
想得到这种效果。数组hths中元素按fphms中元素对应排序,hths中元素重复时,将对应fphms中的元素进行拼接
QAXSZ230811B/23088:666QAXSZ230811A/23079:36357132_36357333
QAXSZ230328A/23039: 36356847_36356864
[此贴子已经被作者于2023/9/14 10:57:16编辑过]
Dim hths() As String = {"QAXSZ230811B/23088", "QAXSZ230811A/23079", "QAXSZ230811A/23079", "QAXSZ230328A/23039", "QAXSZ230328A/23039"}
Dim fphms() As String = {"666", "36357132", "36357333", "36356847", "36356864"}
Dim dic As New Dictionary(Of String, list(Of String))
For i As Integer = 0 To hths.count - 1
Dim lst As New List(Of String)
If dic.ContainsKey(hths(i)) Then
lst = dic(hths(i))
lst.Add (fphms(i))
dic(hths(i)) = lst
Else
lst.Add(fphms(i))
dic.Add(hths(i), lst)
End If
Next
For Each k As String In dic.Keys
Output.Show (k & ":" & String.Join ("_" , dic(K)))
Next