我想从textbox16.text
中删除以逗号分隔的重复项。在一行中(文本框不是多行)。
Dim lines As New List(Of String)(TextBox16.Text)
TextBox16.Clear()
TextBox16.Text = (From s As String In Text).Distinct.ToArray
此代码有什么问题?
答案 0 :(得分:0)
首先对您发布的代码发表评论。
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
'This line will not compile, there is no such syntax
'Dim lines As New List(Of String)(TextBox16.Text)
Dim lines As New List(Of String) From {TextBox16.Text}
'So now you have a list with one item, What do you want to do with it?
'You never use lines
TextBox2.Clear()
'This line will not compile. What do you think Text is?
'If you were thinking Text is the Text property of TextBox16 you have just cleared it.
'But Text is not anything the way you are using it; it is not associated with anything.
'The .ToArray makes no sense. You can't put an array in the Text property of a TextBox.
'You can only put a String in a Text property
'TextBox2.Text = (From s As String In Text).Distinct.ToArray
End Sub
现在一些希望可以运行的代码。
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
Dim spacesRemoved = TextBox16.Text.Replace(" ", String.Empty)
'.Split returns an array of String based on the Char provided (a comma in this case)
Dim items = spacesRemoved.Split(","c)
Dim distinctItems = items.Distinct
Dim newText = String.Join(",", distinctItems)
TextBox16.Text = newText
End Sub