Value between two spaces in a String

K

kathy.aubin

Hi,

I have string like that :

NESN 380.7 STR 01/28/2008

and I want to be able to grab the value between the first two spaces;
380.7. I know how to find the first space but I don't know how to find
the second one.

Does anyone know?

Thanks,

Kathy
 
N

NickHK

Kathy,
Fuction GetPart(InputStr as string, Position as long, Optional Delim as
string=" ") as string
GetPart=Split(InputStr,Delim)(position)
'Add error handling in case invalid values
End Function

So call it with :
Dim Val as variant
Val=GetPart("NESN 380.7 STR 01/28/2008",2)

NickHK
 
B

Bernie Deitrick

Nick,

Nice, except Split returns a 0 based array, so you should use

GetPart=Split(InputStr,Delim)(position - 1)

HTH,
Bernie
MS Excel MVP
 
N

NickHK

Bernie,
Yeah, it's getting late here. And not testing what you write, however
(apparently) simple.
Thanks

NickHK
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top