Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vb.net split last part of the string

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)`
like image 336
Timothy Staudt Avatar asked Jan 04 '13 21:01

Timothy Staudt


2 Answers

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)
like image 142
shf301 Avatar answered Nov 14 '22 10:11

shf301


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

like image 3
urbanspr1nter Avatar answered Nov 14 '22 10:11

urbanspr1nter