• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 183
  • Last Modified:

VB.Net string parsing question

I'm having trouble parsing this string.

I need to get rid of the filename part of the following string, everything to the right of the last "\".

C:\JB\CustData\csv\Neill.csv

I'm coding this with VB.Net

thanks,
JMO9966
0
JMO9966
Asked:
JMO9966
  • 2
2 Solutions
 
PaulHewsCommented:
Really easy in .NET using the path class

Dim path As String = "C:\JB\CustData\csv\Neill.csv"

MsgBox(System.IO.Path.GetFileName(path))
0
 
Bob LearnedCommented:
Actually, I believe that would be System.IO.Path.GetDirectoryName(path).

Bob
0
 
PaulHewsCommented:
Woops.  Yes, if he actually wants to get *rid* of the filename part, like he says in the question, instead of in the sentence that arrived in my mind...
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
You can also pass the filename to a new FileInfo instance and get the info from that:

        Dim fullPath As String = "C:\JB\CustData\csv\Neill.csv"
        Dim fi As New System.IO.FileInfo(fullPath)
        Dim fileName As String = fi.Name
        Dim filePath As String = fi.DirectoryName
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!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now