示例:说我有一个文本框,其中包含文本“visual basic”有没有办法我可以删除“基本”或即使我不知道文本有没有办法我可以删除最后5个或更多或更少在文本框中?
试试这个:
MyString = TextBox1.Text
TextBox1.Text = MyString.Left(MyString.Length - 5)
如果Left
不起作用,试试这个:
MyString = TextBox1.Text
If MyString.Length < 5 Then
TextBox1.Text = MyString.SubString(5, str.Length - 5)
End If
如果你想删除最后一个单词
Dim words AS String() = YourTextBox.Text.Split(" "c)
YourTextBox.Text = String.Join(" ", words.Take(words - 1))
如果你想删除一些最后的字符
Dim amountToRemove As Integer = 5
YoutTextBox.Text = YoutTextBox.Text.Remove(YoutTextBox.Text.Length - amountToRemove)
或LINQ方法
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)