split command in visual basic

anjali5
10-11-2009, 02:25 PM
Hello Everyone,

I want to use split command in Visual basic. I have a c:/program/abc/wef/add.doc

I want to get the name add.doc, for getting that name, I want to do split on "/". This directory path
can have multiple "/"since it is coming from database.

How do I use split command.

Thanks.

gibra
10-11-2009, 02:59 PM
Try this:

Dim sFilePath As String
Dim sAr() As String

sFilePath = "c:/program/abc/wef/add.doc"
sAr = Split(sFilePath, "/")

Debug.Print "Filename is: " & sAr(UBound(sAr))

In Immediate window will return

Filename is add.doc

Roger_Wgnr
10-11-2009, 05:12 PM
No need to split to an array just use InStrRev.
Dim sFilePath As String
Dim sFilename As String

sFilePath = "c:/program/abc/wef/add.doc"
sFilename = Mid(sFilePath, InStrRev(sFilePath, "\") + 1)

Debug.Print "Filename is: " & sFilename

Flyguy
10-12-2009, 12:36 PM
That will only work in .Net, this is for legacy VB ;)

darkforcesjedi
10-12-2009, 01:37 PM
Oops... my erroneous post above is deleted.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum