2013-01-04 47 views
3

net 2.0並需要分割字符串的最後一個/標記。目前我有一個代碼,說Dim test As String = "Software\Microsoft\Windows\Welcome",需要一個代碼,將軟件\微軟\ Windows \歡迎分爲兩個單獨的部分末尾 因此,我將軟件\微軟\ Windows和歡迎作爲新的字符串。 我只能找到的東西,將剩下的分裂開始像vb.net分割字符串的最後一部分

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)` 

回答

10

使用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) 
+2

+1。這是最簡單的方法。 – Neolisk

+0

感謝您的回答 –

2

嘗試分裂「\」作爲您的分隔符並將其存儲爲一個字符串數組。然後抓住最後一個元素,它應該是「歡迎」。