以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  [求助]字符数组处理  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=188324)

--  作者:kuroneko
--  发布时间:2023/9/14 10:47:00
--  [求助]字符数组处理
想将相同合同号对应的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 

--  作者:y2287958
--  发布时间:2023/9/14 10:50:00
--  
想得到啥结果?
--  作者:kuroneko
--  发布时间:2023/9/14 10:54:00
--  
想得到这种效果。数组hths中元素按fphms中元素对应排序,hths中元素重复时,将对应fphms中的元素进行拼接
QAXSZ230811B/23088:666
QAXSZ230811A/23079:36357132_36357333
QAXSZ230328A/23039: 36356847_36356864
[此贴子已经被作者于2023/9/14 10:57:16编辑过]

--  作者:y2287958
--  发布时间:2023/9/14 11:18:00
--  
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 

--  作者:kuroneko
--  发布时间:2023/9/14 12:13:00
--  
谢谢爸