0

至于问题,这甚至可能吗?我正在做这个..

它应该只是“UP”,但由于我的分隔符是 = 它只读取 = ,所以它继续获得第二行,即 DHCP。

这是我的代码..

Private Sub btnSettings_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSettings.Click
    Dim str As String = rtb.Text
    Dim star() As String

        star = str.Split("="c)
        txtIP.Text = star(1)

End Sub

有没有办法可以在不同的分隔符之间获取一个字符串?
例如 = 192.168.254.238 :

4

3 回答 3

1

在stackoverflow的一些c#页面上找到它。刚刚添加了另一个分隔符,虽然我不知道它是否适用于三个。干杯!

Private Sub btnSettings_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSettings.Click
    Dim str As String = rtb.Text
    Dim star() As String
    ''Dim starr() As String
    star = str.Split("="c, ":"c)
    ''starr = str.Split(":"c)
    txtIP.Text = star(4)

End Sub
于 2013-11-04T08:03:02.683 回答
0

首先拆分vbcrlf- 你得到线,然后for-each线,拆分=- 你得到键/值。

于 2013-11-04T07:43:38.270 回答
0

我不完全是你想要的,但试试这个:

 For Each line As String In RichTextBox1.Lines
     Dim star() As String = line.Split("=")
     If (star(0).ToUpper() = "IP") Then
         If (star(1).IndexOf(":") >= 0) Then
            txtIP.Text = star(1).Substring(0, star(1).IndexOf(":"))
         Else
            txtIP.Text = star(1)
         End If
     End If
 Next
于 2013-11-04T07:35:27.690 回答