Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 189
  • Last Modified:

Seach for Space in a string

I'm new to VB and I need to know how to extract text from a string after a space is detected.

For example "123 456" would result in "456"

or "12345 6789" would result in "6789"

Thank you.  
0
Jake28
Asked:
Jake28
  • 2
1 Solution
 
DeAnCommented:
MsgBox Mid(Text1.Text, InStrRev(Text1.Text, " ") + 1)
0
 
DeAnCommented:
Dim MyString as String
MyString = "12345 67890"
MsgBox Mid(MyString , InStrRev(MyString , " ") + 1)

' MsgBox displays "67890"
0
 
Jake28Author Commented:
I should have explained my question better.

DeAn's code works fine:

Dim MyString as String
MyString = "12345 67890"
MsgBox Mid(MyString , InStrRev(MyString , " ") + 1)

But what if I have several spaces in my string.

For example: from "123 456 7890" I would want "456 7890" as the result. The number of spaces in the string varies but I always want the remainder after the first space.

0
 
MN_DaveCommented:
Instead of this:

MsgBox Mid(MyString , InStrRev(MyString , " ") + 1)

Use this:

MsgBox Mid(MyString , InStr(MyString , " ") + 1)
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now