0
我有一个StringBuilder我正在使用,我从一个循环通过DataGridView添加到它。我需要做的是分离字符串,如果有多于一个“,”。然后我从StringBuilder中设置一个标签的文本。下面是没有逗号的工作示例...如何分隔字符串生成器中的字符串?
这是更新版本的伟大工程.... NOW
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()
谢谢,这就是我已经在努力,只是要把它放在正确的位置。发生了什么是它会添加字符串之间的逗号,但也是最后一个我不想要的。我编辑了上面的代码,以显示我做了什么并且效果很好。再次感谢! – Codexer