我正在使用VB.NET代码.
我有以下字符串.
http://localhost:3282/ISS/Training/SearchTrainerData.aspx
Run Code Online (Sandbox Code Playgroud)
现在我想用"/"分割上面的字符串.我想将值SearchTrainerData.aspx存储在变量中.
就我而言
Dim str as String
str = "SearchTrainerData.aspx"
Run Code Online (Sandbox Code Playgroud)
什么是将上述字符串拆分并进一步存储在变量中的代码?
您的"字符串"显然是一个URL,这意味着您应该使用System.Uri类.
Dim url As Uri = New Uri("http://localhost:3282/ISS/Training/SearchTrainerData.aspx")
Dim segments As String() = url.Segments
Dim str As String = segments(segments.Length - 1)
Run Code Online (Sandbox Code Playgroud)
这也将允许您获取有关"字符串"的各种其他有趣信息,而无需使用手动(并且容易出错)解析.