Extract filenames from a string

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • SAIRAAM
    New Member
    • Feb 2007
    • 45

    Extract filenames from a string

    hi all...

    i have got arequirement where in i need to take out the file names alone from a given string... i thought of using indexof function but not sure of its exact usage...

    eg

    there are two paths like this

    str="c:\windows \temp c:\windows\dir"

    i need to get the file names alone as outputs that is temp and dir...

    i tried giving the index of fuction like this but its not working

    int len
    len=str.indexof (" ")
    string str1
    str1=str.substr ing(0,len)


    but this code is not working...can anyone suggest me a solution..

    wiill be thankful to whatever help i get

    thanks

    sairaam
  • Killer42
    Recognized Expert Expert
    • Oct 2006
    • 8429

    #2
    The Split() function will allow you to split the string at a given character (such as a space). However, this might be a problem if the filenames contain spaces.

    Comment

    • SAIRAAM
      New Member
      • Feb 2007
      • 45

      #3
      Originally posted by Killer42
      The Split() function will allow you to split the string at a given character (such as a space). However, this might be a problem if the filenames contain spaces.
      THANKS FOR UR HELP...I DONT CLEARLY GET YOU..CAN YOU QUOTE ME WITH SOME EXAMPLE... IT WOULD BE STILL MORE HELPFUL..

      SAIRAAM

      Comment

      • asheeshpanwar2008
        New Member
        • May 2007
        • 3

        #4
        this will like this
        str=strreverse( str)
        str=mid(str,1,i nstr(1,str,"/")-1)
        str=strreverse( str)
        it will help u

        Comment

        • Killer42
          Recognized Expert Expert
          • Oct 2006
          • 8429

          #5
          Here's a very simple example (from VB6) of how the Split() function can be used to pull the string apart...
          Code:
          Debug.Print Split("c:\windows\temp c:\windows\dir", " ")(0)
          Debug.Print Split("c:\windows\temp c:\windows\dir", " ")(1)

          Comment

          • SAIRAAM
            New Member
            • Feb 2007
            • 45

            #6
            Originally posted by Killer42
            Here's a very simple example (from VB6) of how the Split() function can be used to pull the string apart...
            Code:
            Debug.Print Split("c:\windows\temp c:\windows\dir", " ")(0)
            Debug.Print Split("c:\windows\temp c:\windows\dir", " ")(1)
            thanks a lot sir i am able to get it now... thanks for your guidence

            sairaaam

            Comment

            Working...