Link to home
Start Free TrialLog in
Avatar of eneate
eneateFlag for United Kingdom of Great Britain and Northern Ireland

asked on

how do i split a string to get the text after the last \ symbol - vb6

Hi

Usinf vb 6 how would i split a string that looked like c:\test\ghtf\jsjghdj to get all of the text after the last \ symbol. The length of the string and the number of these strings could vary
Thanks
ASKER CERTIFIED SOLUTION
Avatar of nffvrxqgrcfqvvc
nffvrxqgrcfqvvc

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of nffvrxqgrcfqvvc
nffvrxqgrcfqvvc

Missed the last element only in your question. To get the last element you can use the following.

Debug.Print args(UBound(args))

Open in new window

dim tail as string
tail = mid("\"+YourString,Instrrev("\"+YourString,"\")+1)
Try this:


    Dim str1 As String
    Dim str2 As String
    str1 = "c:\test\ghtf\jsjghdj"
    str2 = StrReverse(str1)
    str2 = StrReverse(Left(str2, InStr(1, str2, "\") - 1))

Open in new window

Avatar of GrahamSkan
Alternatively:


Dim strText As String
Dim p As Integer
Dim strLastBit As String

strText = "c:\test\ghtf\jsjghdj"
p = InStrRev(strText, "\")
strLastBit = Mid$(strText, p + 1)

Open in new window

Looks like some good solutions. The way I do it is
For X = Len(S) to 1 Step -1
    If Mid$(S,X,1) = "\" Then
        P = X
        Exit For
    End if
Next X
E = Mid$(S, P + 1)
where S is your initial string, X and P are intergers, and E is a string to hold the end of S after the \.
 
Avatar of eneate

ASKER

Thanks it works fine. Thanks to everyone else who contributed.