3列のデータテーブルがあります
Id name value value1
このデータテーブルから文字列を作成して、
- データテーブルの各行は 2 つの行を作成します
- 名前が1行になる
- 値 1 は別の行になります
name と value1 が類似している場合は、値 1 のみを含めます。それ以外の場合は、name と value1 の両方を含めます (これは行われます)。
ある行の名前が他の行の名前と似ている場合は、文字列内の両方の重複行の前に次のテキストを追加します
Id は Id に似ています
これは私がこれまでに書いたものです:
Public Function GetGazetteer(dataTable As DataTable) As String
Dim processedData = New List(Of String)
Dim rowData = String.Empty
Dim results = New StringBuilder()
For Each row As DataRow In dataTable.Rows
processedData.Add(row(1))
If row(3) <> row(1) Then
processedData.Add(row(3))
End If
Next
For Each row As String In processedData
rowData = row
If rowData.Trim <> String.Empty Then
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
End If
Next
Return results.ToString
End Function
現在、*
が追加されています (上記のテキストを追加する方法を提案してください。)
ここにサンプルがあります
id name value value1
1 this is string 1 abc This is sample
2 this is string 2 abc this is string 2
3 this is string 3 abc this is string 4
4 this is string 3 abc asasaasd
ここに望ましい出力があります
this is string 1
This is sample
this is string 2
*3 is duplicate of 4* this is string 3
this is string 4
*4 is duplicate of 3* this is string 3
asasaasd