Cut a string at a certain character and return it

chatko
chatko used Ask the Experts™
on
I would like a simple method that given a string and a character would return a string containing everything in the original string until the first occurance of the said character

example: string1= "C:\Testa"

parameters sent: string1 and "a"

return: "C:\Test"

Thanks

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2006
Commented:
Hello chatko,

you could try

Function RetStrPart(ByVal SearchString As String, ByVal SearchChar As String)
Dim i As Integer
i = InStr(1, SearchString, SearchChar, 1) - 1
RetStrPart = Left(SearchString, i)
End Function

HAGD:O)Brintje

Author

Commented:
Works like a charm, thanks

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial