Reputation: 1
Is there any way that I can delete the last "word" in a textbox? Each word or string would be separated by a comma (",")
This is what I have at the minute, but I am open to new suggestions
Dim deleteItem() As String = Split(TextBox2.Text, ", ")
Array.Resize(deleteItem, deleteItem.Length - 1)
For i = 0 To UBound(deleteItem)
TextBox2.Text = deleteItem(i)
Next
Any help would be great thanks :)
Upvotes: 0
Views: 167
Reputation: 15923
Why dont you just get the substring till the last ,
TextBox2.Text = TextBox2.Text.Substring(0,TextBox2.Text.LastIndexOf(","))
Upvotes: 1
Reputation: 8004
You can use the LastIndexOf Function
TextBox2.Text = TextBox2.Text.Substring(0,TextBox2.Text.LastIndexOf(",")).Trim()
Upvotes: 1