November 12th, 2009, 05:17 PM
Getting a filename from a string
Hello, I have a list of .exe files and some of them have extra stuff at the end. I was wondering how to get the filename without the stuff at the end.
Here is an example:
I'm not quite sure if regex is the best solution for this, but if it is, could somebody help me out? Thanks.
C:\Windows\system32\svchost.exe -k netsvcs
C:\Program Files\Common Files\Symantec Shared\ccSvcHst.exe /h ccCommon
November 13th, 2009, 10:02 AM
Well not sure if this is the best way, but it seems to work:
[code=vb.net]Dim vFile As String = "C:\Windows\system32\svchost.exe -k netsvcs"
Dim vFilePattern As New Regex("(.*?)\.(exe|dll|drv)", RegexOptions.IgnoreCase)
Dim vMatches As MatchCollection = vFilePattern.Matches(vFile)
If vMatches.Count > 0 Then
Dim vMatch as String = vMatches.Item(0).ToString