Removing everything to left of a string up to a certain character in Visual Studio 2017 (Visual Basic)

Viewed 313

The string in question is a file path take from an xml file.

..\Folder\Folder\Folder\filename.ext

the code I have takes this file path element from each xml entry and adds it to a ListView

what I need to do is remove everything from the left of the last "\" so that all that is added to the ListView is

filename.ext

the file path element is never the same length and doesn't have the same amount of "\" characters every time, with this i mean it could be

..\Folder\Folder\Folder\Folder\biglongfilename.ext

..\Folder\Folder\filename.ext

I have searched and tried some things like the string manipulation stuff

'Dim pos As Integer
'pos = Rname.IndexOf("\") - 1
'Dim RnameSH As String = Rname.Substring(10, pos)

This only gives me correctly if I specify the amount of letters I need (which could be different every time)

        Dim RnameSH As String = ""
        Dim i As Integer
        Dim pos As Integer

        For i = 1 To 200

            If (Microsoft.VisualBasic.Strings.Right(Rname, i)) <> "\" Then

                i = i + 1

            ElseIf (Microsoft.VisualBasic.Strings.Right(Rname, i)) = "\" Then

                pos = i

                'Next i
            End If
        Next i

        RnameSH = Microsoft.VisualBasic.Strings.Right(Rname, pos)

Also tried the old fashion way but that doesn't seem to work.

Nothing I try gives me the filename.ext only that i need. This is my first attempt at real programming and I've read about string manipulation on various sites but i just can't figure this out at all.

Thanks for any help you can give with this or for pointing me in the right direction

0 Answers
Related