Example: say i have a text box that has the text "visual basic" is there a way i can remove "basic" or even if i don't know the text is there a way i can remove the last 5 or more or less in the text box?
Asked
Active
Viewed 3,327 times
-1
-
what does `remove the last 5 or more or less in the text box` mean? Is this a varying number, and what causes it be more or less? – OneFineDay Dec 30 '16 at 05:57
2 Answers
3
If you want remove last word
Dim words AS String() = YourTextBox.Text.Split(" "c)
YourTextBox.Text = String.Join(" ", words.Take(words - 1))
If you want remove some number of last characters
Dim amountToRemove As Integer = 5
YoutTextBox.Text = YoutTextBox.Text.Remove(YoutTextBox.Text.Length - amountToRemove)
Or LINQ approach
Dim amountOfCharactersToRemove As Integer = 5
Dim amountOfCharactersToTake = YourTextBox.Text.Length - amountOfCharactersToRemove
Dim characters As Char() = YourTextBox.Text.
ToCharArray().
Take(amountOfCharactersToTake).
ToArray()
YoutTextBox.Text = new string(characters)

Fabio
- 31,528
- 4
- 33
- 72
-1
Try this:
MyString = TextBox1.Text
TextBox1.Text = MyString.Left(MyString.Length - 5)
If Left
doesn't work, try this:
MyString = TextBox1.Text
If MyString.Length < 5 Then
TextBox1.Text = MyString.SubString(5, str.Length - 5)
End If

Vincent Thacker
- 393
- 1
- 13