Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Extract part of string

Status
Not open for further replies.

tamtf

Programmer
Jun 25, 2002
10
0
0
US
how can I extract from the string below the character between the first dash and the second?
string= GP - 87415A - greene - r
result= 87415A
Is there a function available?
Thank you for your help.
tamtf
 
You can use the Instr function to find the position of the '-' character, then use Mid function to extract the section you want.

They are both well documented in VBHelp
________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
You can try using the split function as well.

dim strArray() as string
strarray =split(string,"-")

will give you

strArray(0) = "GP "
strArray(1) = " 87415A "
strArray(2) = " greene "
strArray(3) = " r"

You will need to know which element you want, then you can use the trim function to get rid of the spaces.

Thanks and Good Luck!

zemp
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top