How to split in VB.NET

前端 未结 5 2147
别跟我提以往
别跟我提以往 2020-12-21 19:16

I am using VB.NET code.

I have got the below string.

http://localhost:3282/ISS/Training/SearchTrainerData.aspx

Now I want to split

相关标签:
5条回答
  • 2020-12-21 19:20

    Your "string" is obviously a URL which means you should use the System.Uri class.

    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)
    

    This will also allow you to get all kinds of other interesting information about your "string" without resorting to manual (and error-prone) parsing.

    0 讨论(0)
  • 2020-12-21 19:24

    The Split function takes characters, which VB.NET represents by appending a 'c' to the end of a one-character string:

    Dim sentence = "http://localhost:3282/ISS/Training/SearchTrainerData.aspx"
    Dim words = sentence.Split("/"c)
    Dim lastWord = words(words.length - 1)
    
    0 讨论(0)
  • 2020-12-21 19:27

    Use split(). You call it on the string instance, passing in a char array of the delimiters, and it returns to you an array of strings. Grab the last element to get your "SearchTrainerData.aspx."

    0 讨论(0)
  • 2020-12-21 19:28

    I guess what you are actually looking for is the System.Uri Class. Which makes all string splitting that you are looking for obsolete.

    MSDN Documentation for System.Uri

    Uri url = new Uri ("http://...");
    String[] parts = url.Segments;
    
    0 讨论(0)
  • 2020-12-21 19:38

    Try to use the function String.Split.

    0 讨论(0)
提交回复
热议问题