在 c# 中回答也对我有帮助。
我尝试了这段代码,如果我在多个数组列表中有重复的字符串,它会像以前一样按顺序更新和显示。
maths
english
maths
hindi
english
science
Economics
scince
我需要这样的输出
maths_1
english_1
maths_2
hindi
science_1
Economics
scince_2
我试过这段代码,但输出不按顺序**
Dim subjectCounts As Dictionary(Of String, Integer) = New Dictionary(Of String, Integer)
For Each subject As String In arraysub
If subjectCounts.ContainsKey(subject) Then
subjectCounts(subject) = (subjectCounts(subject) + 1)
Else
subjectCounts.Add(subject, 1)
End If
Next
Dim output As List(Of String) = New List(Of String)
For Each pair As KeyValuePair(Of String, Integer) In subjectCounts
If (pair.Value > 1) Then
Dim i As Integer = 1
Do While (i <= pair.Value)
output.Add((i.ToString + ("_" + pair.Key)))
i = (i + 1)
Loop
Else
output.Add(pair.Key)
End If
Next