vb.net string help

Hello All:

I have following the following string value

I just want to grab the file name and put in a different string variable

Thu 07/09/2015 11:35:45.83 - Missing file: "x:\TAD Image\Alldocs\utility\H155559ZK.TXT" 

Open in new window


output

H155559ZK.TXT

Open in new window

LVL 5
CalmSoulAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

MasonWexlerCommented:
How about something like this?

        Dim str1 As String = "Thu 07/09/2015 11:35:45.83 - Missing file: ""x:\TAD Image\Alldocs\utility\H155559ZK.TXT"
        Dim pos1 As Integer = str1.LastIndexOf("\") + 1
        Dim str2 As String = str1.Remove(0, pos1)
0
it_saigeDeveloperCommented:
Probably something like this:
Imports System.IO
Imports System.Runtime.CompilerServices

Module Module1
	Sub Main()
		Dim errorMessage = "Thu 07/09/2015 11:35:45.83 - Missing file: ""x:\TAD Image\Alldocs\utility\H155559ZK.TXT"""
		Console.WriteLine(errorMessage.GetErrorMessageFileName("Missing file:"))
		Console.ReadLine()
	End Sub
End Module

Module Extensions
	<Extension()> _
	Public Function GetErrorMessageFileName(ByVal source As String, ByVal filter As String) As String
		Dim file As FileInfo
		Dim result As String = String.Empty
		Dim index = source.IndexOf(filter, StringComparison.OrdinalIgnoreCase) + filter.Length
		If index <> -1 Then
			Try
				file = New FileInfo(source.Substring(index, source.Length - index).Trim().Trim(""""))
				If file IsNot Nothing Then
					result = file.Name
				End If
			Catch ex As Exception
				result = String.Empty
			End Try
		End If
		Return result
	End Function
End Module

Open in new window

Which produces the following -Capture.JPG-saige-
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
zalazarCommented:
You could also do it like this.

Module Module1
    Sub Main()
        Dim strMessage = "Thu 07/09/2015 11:35:45.83 - Missing file: ""x:\TAD Image\Alldocs\utility\H155559ZK.TXT"""
        Dim vPos1 As Integer = strMessage.LastIndexOf("\")
        If vPos1 > 0 Then
            Dim str2 As String = Replace(Mid(strMessage, vPos1 + 2), Chr(34), "")
            Console.WriteLine(str2)
        Else
            Console.WriteLine("ERROR Could not find \ character in: " & strMessage)
        End If
        Console.ReadLine()
    End Sub
End Module

Open in new window

0
Mike TomlinsonMiddle School Assistant TeacherCommented:
...and yet another one:
Dim data As String = "Thu 07/09/2015 11:35:45.83 - Missing file: ""x:\TAD Image\Alldocs\utility\H155559ZK.TXT"""
Dim fileName As String = data.Split("\").Last.TrimEnd("""")
MessageBox.Show(fileName)

Open in new window

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.