我有一个正在使用的 StringBuilder,我从一个通过 DataGridView 的循环添加到它。如果有多个带有“,”的字符串,我需要做的是分隔字符串。然后我从 StringBuilder 设置标签的文本。下面是一个没有逗号的工作示例......
这是现在很好用的更新版本....
Dim strUnits As New System.Text.StringBuilder
Dim lineCount As Integer = 0
For i = 0 To dgvLowInventory.RowCount - 1
If dgvLowInventory.Rows(i).Cells(1).Value Is DBNull.Value Or dgvLowInventory.Rows(i).Cells(2).Value Is DBNull.Value Then
'Skip
Else
If lineCount >= 1 Then
strUnits.Append(", ")
strUnits.Append("[" & dgvLowInventory.Rows(i).Cells(1).Value & " - " & dgvLowInventory.Rows(i).Cells(3).Value & "]")
lineCount += 1
Else
strUnits.Append("[" & dgvLowInventory.Rows(i).Cells(1).Value & " - " & dgvLowInventory.Rows(i).Cells(3).Value & "]")
lineCount += 1
End If
End If
Next
lblTestString.Text = strUnits.ToString()