Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. "LastIndexOf" doubt

"LastIndexOf" doubt

Scheduled Pinned Locked Moved C#
xmltutorial
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jayarajmrj
    wrote on last edited by
    #1

    string strPath = @"D:\XML Tutorial(Basics).doc"; string strFileName = strPath.Substring(strPath.LastIndexOf("\\") + 1); Here it works fine to separate the filename. Apart from "LastIndexOf", Is there any method to split the filename from the path. pls give the solution ASAP

    M N H 3 Replies Last reply
    0
    • J jayarajmrj

      string strPath = @"D:\XML Tutorial(Basics).doc"; string strFileName = strPath.Substring(strPath.LastIndexOf("\\") + 1); Here it works fine to separate the filename. Apart from "LastIndexOf", Is there any method to split the filename from the path. pls give the solution ASAP

      M Offline
      M Offline
      Martin 0
      wrote on last edited by
      #2

      Hello, to split a string, you would use the: String.Split[^] method. Dealing with filename and pathes you could use the fancy features of System.IO.Path[^] namespace! In your case, the GetFileName[^] method will do what you need. string strPath = @"D:\XML Tutorial(Basics).doc"; string strFileName = System.IO.Path.GetFileName(strPath ); /will return: 'XML Tutorial(Basics).doc' Hope it helps!

      All the best, Martin

      1 Reply Last reply
      0
      • J jayarajmrj

        string strPath = @"D:\XML Tutorial(Basics).doc"; string strFileName = strPath.Substring(strPath.LastIndexOf("\\") + 1); Here it works fine to separate the filename. Apart from "LastIndexOf", Is there any method to split the filename from the path. pls give the solution ASAP

        N Offline
        N Offline
        N a r e s h P a t e l
        wrote on last edited by
        #3

        Hi, Use the following: string filename=System.IO.Path.GetFileName("YourFilePath");

        Naresh Patel

        1 Reply Last reply
        0
        • J jayarajmrj

          string strPath = @"D:\XML Tutorial(Basics).doc"; string strFileName = strPath.Substring(strPath.LastIndexOf("\\") + 1); Here it works fine to separate the filename. Apart from "LastIndexOf", Is there any method to split the filename from the path. pls give the solution ASAP

          H Offline
          H Offline
          Hessam Jalali
          wrote on last edited by
          #4

          you can use System.IO.Path Class to do that like string path=@"C:\my Pics\test.bmp"; string fileName=System.IO.Path.GetFileName(path); good luck

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups