Hello,

I'm new to vb.

Basically, I want to learn how to remove the last part of a string if its seperated by spaces...

For Example (How to change):

"John said 687" To "687"

or

"John decided to say hello" To "hello"

in otherwords, the last word of the string, it won't always be the same number of digits/letters though, but it will always be seperated by a space.


Ask if you have questions.
Thanks in advance.

Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
    Const input As String = "John said 687"
    Dim words() As String = input.Split(New [Char]() {" "c}, System.StringSplitOptions.None)
    Dim lastWord As String = words(words.Length - 1)
    MessageBox.Show(lastWord)
  End Sub
Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
    Const input As String = "John said 687"
    Dim words() As String = input.Split(New [Char]() {" "c}, System.StringSplitOptions.None)
    Dim lastWord As String = words(words.Length - 1)
    MessageBox.Show(lastWord)
  End Sub

Thanks.

Thanks.

You're welcome.

Please mark this thread as solved if you have found an answer to your question and good luck!

Dim words() As String = input.Split(New [Char]() {" "c}, System.StringSplitOptions.None)

we can only write

Dim words() As String = input.Split(" ")

This question has already been answered. Start a new discussion instead.