string extraction

vb6 Grenada
  • 14 years ago
    hi,
    i have  strings of this kind "E:\new.txt","E:\temp\abcd.txt","E:\temp\cur\sss.txt" is it possible to extract only file names from those strings like new.txt,abcd.txt,sss.txt like this.
    Thank u in advance

  • 14 years ago
    All you have to do is break the string up using split using the backslash as the splitter.  The last position of the array now contains the filename:

    Private Sub Command1_Click()
    Dim strSplitPath() As String
    Dim strPathName As String
    strPathName = "E:\temp\cur\sss.txt"
    strSplitPath = Split(strPathName, "\")
    Dim strFileName As String
    strFileName = strSplitPath(UBound(strSplitPath))
    Label1.Caption = strFileName
    End Sub

    You will need to put some error checking in to check that the filename contains a backslash using InStr.











  • 14 years ago
    It is better to use File System Object (FSO) for this purpose

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.” - Rick Osborne