vb.net split last part of the string

20,038

Solution 1

Use String.LastIndexOf()

Dim whole As String = "Software/Microsoft/Windows/Run"
Dim firstpart As String = whole.Substring(0, whole.LastIndexOf("/"))
Dim lastpart As String = whole.Substring(whole.LastIndexOf("/") + 1)

Solution 2

Try splitting with '\' As your delimeter and store it as a string array. Then just grab the last element and it should be "Welcome".

Share:
20,038
Timothy Staudt
Author by

Timothy Staudt

Updated on July 05, 2022

Comments

  • Timothy Staudt
    Timothy Staudt almost 2 years

    net 2.0 and need to split the last / mark of the string. Currently I have a code that says Dim test As String = "Software\Microsoft\Windows\Welcome" and need a code that will split that Software\Microsoft\Windows\Welcome into two separate section at the end So I'll have Software\Microsoft\Windows and Welcome as new strings. I can only find things that will split the beginning from the rest like

    Dim whole As String = "Software/Microsoft/Windows/Run"
    Dim firstpart As String = whole.Substring(0, whole.IndexOf("/"))
    Dim lastpart As String = whole.Substring(whole.IndexOf("/") + 1)`