在我的示例中,我使用了一个包含数据的数组,但只需将数组部分替换为您的 DataTable 就可以了。基本上,您使用 DataTable 信息构建一个字符串列表,然后使用 LINQ 检查该数据是否已经存在一次或多次。
Dim data As String() = {"A", "B", "C", "D", "E", "A", "E", "F", "G", "H", "A", "A", "B", "X", "Y", "Z"}
Dim processedData = New List(Of String)
Dim rowData = String.Empty
Dim results = New StringBuilder()
For Each row As String In data
processedData.Add(row)
Next
For Each row As String In processedData
rowData = row
If (processedData.Where(Function(d) d = rowData).Count = 1) Then
results.Append(rowData)
results.Append("<br />")
Else
results.Append(rowData)
results.Append("*")
results.Append("<br />")
End If
Next
结果字符串是
A*<br />
B*<br />
C<br />
D<br />
E*<br />
A*<br />
E*<br />
F<br />
G<br />
H<br />
A*<br />
A*<br />
B*<br />
X<br />
Y<br />
Z<br />