Vb.net 代码通过单词提取每行的值

Vb.net 代码通过单词提取每行的值,vb.net,filter,Vb.net,Filter,textbox1.text= | 212.55.11.51:8080 | vpn | http | | 212.55.11.52:8080 | rte | http | | 212.55.11.53:8080 | dfg | http | | 212.55.11.54:8080 | vpn | http | | 212.55.11.55:8080 | vpn | http | | 212.55.11.56:8080 | Tyu | http | | 212.55.11.57:8080 | RFe

textbox1.text=

| 212.55.11.51:8080 | vpn | http |
| 212.55.11.52:8080 | rte | http |
| 212.55.11.53:8080 | dfg | http |
| 212.55.11.54:8080 | vpn | http |
| 212.55.11.55:8080 | vpn | http |
| 212.55.11.56:8080 | Tyu | http |
| 212.55.11.57:8080 | RFe | http |
| 212.55.11.58:8080 | vpn | http |
我需要工作代码。 当你写这个词的时候。 通过文本框2,按下按钮

IP地址显示在线路上。 上述示例的一个示例是继续8行,其中包含4行中的vpn一词

下一步显示所有IP地址
212.55.11.51
212.55.11.54
212.55.11.55
212.55.11.58


在列表框内部

可以使用LINQ和
字符串。拆分

Dim lines = text.Split({Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries)
Dim matchingIPs = From line In lines
                  Let tokens = line.Split({"|"}, StringSplitOptions.RemoveEmptyEntries)
                  Let IP = tokens(0).Trim()
                  Let type = tokens(1).Trim()
                  Where type = "vpn"
                  Select IP.Split(":"c)(0).Trim()

listBox1.Items.AddRange(matchingIPs.ToArray())

到目前为止你试过什么?解决这个问题的一个最好的方法是使用一个字典,其中的密钥是“vpn”,例如,然后保存一个值,该值将是ip地址列表。然后,当您使用ContainsKey(“Vpn”)时,您可以使用密钥索引器(即myDict[“Vpn”])来获取列表值,并且对于列表中的每个项目,将其添加到列表框中。