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

Posted on 2010-08-12
Last Modified: 2013-12-26

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
Question by:eneate
LVL 29

Accepted Solution

nffvrxqgrcfqvvc earned 500 total points
ID: 33422655
You can try below example. If you want to skip the root drive start enumeration at the first element instead of zero.
dim myString as string
dim args() as string
dim i as long
for i = lbound(args) to ubound(args)
debug.print args(i)
next i

Open in new window

LVL 29

Expert Comment

ID: 33422700
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

LVL 42

Expert Comment

ID: 33423037
dim tail as string
tail = mid("\"+YourString,Instrrev("\"+YourString,"\")+1)
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

LVL 17

Expert Comment

ID: 33423038
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

LVL 76

Expert Comment

ID: 33423099

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


Expert Comment

ID: 33423292
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 \.

Author Closing Comment

ID: 33423625
Thanks it works fine. Thanks to everyone else who contributed.

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Excel object stays open 19 73
Microsoft Access combo box help 2 44
How to measure sizes and angles in scanned images ? 3 63
Set email body to html using vbscript 6 41
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question