Split a string in VB.NET

前端 未结 3 1621
轮回少年
轮回少年 2020-12-06 10:38

I am trying to split the following into two strings.

\"SERVER1.DOMAIN.COM Running\"

For this I use the code.

Dim Str As Str         


        
3条回答
  •  渐次进展
    2020-12-06 11:26

    Here's a method using Regex class:

        Dim str() = {"SERVER1.DOMAIN.COM Running", "mydomainabc.es     not-running"}
        For Each s In str
            Dim regx = New Regex(" +")
            Dim splitString = regx.Split(s)
            Console.WriteLine("Part 1:{0}  |  Part 2:{1}", splitString(0), splitString(1))
        Next
    

    And the LINQ way to do it:

        Dim str() = {"SERVER1.DOMAIN.COM Running", "mydomainabc.es     not-running"}
        For Each splitString In From s In str Let regx = New Regex(" +") Select regx.Split(s)
            Console.WriteLine("Part 1:{0}  |  Part 2:{1}", splitString(0), splitString(1))
        Next
    

提交回复
热议问题