6

net 2.0 并且需要拆分字符串的最后一个 / 标记。目前我有一个代码,Dim test As String = "Software\Microsoft\Windows\Welcome"需要一个代码,将 Software\Microsoft\Windows\Welcome 拆分为最后两个单独的部分,所以我将 Software\Microsoft\Windows 和 Welcome 作为新字符串。我只能找到将开始与其余部分分开的东西,例如

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

2 回答 2

15

使用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)
于 2013-01-04T22:03:30.367 回答
3

尝试使用 '\' 作为分隔符拆分并将其存储为字符串数组。然后抓住最后一个元素,它应该是“欢迎”。

于 2013-01-04T22:02:46.687 回答