[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

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

Posted on 2010-08-12
7
Medium Priority
?
306 Views
Last Modified: 2013-12-26
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
0
Comment
Question by:eneate
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 29

Accepted Solution

by:
nffvrxqgrcfqvvc earned 2000 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
myString="c:\eat\more\ziti"
args()=Split(mystring,"\")
for i = lbound(args) to ubound(args)
debug.print args(i)
next i

Open in new window

0
 
LVL 29

Expert Comment

by:nffvrxqgrcfqvvc
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

0
 
LVL 42

Expert Comment

by:dqmq
ID: 33423037
dim tail as string
tail = mid("\"+YourString,Instrrev("\"+YourString,"\")+1)
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 17

Expert Comment

by:Zhaolai
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

0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 33423099
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

0
 
LVL 5

Expert Comment

by:Leithauser
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 \.
 
0
 

Author Closing Comment

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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses

649 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