如何从文本文件第二行中选择第一个字符串 [英] How do I select from a text file second row only first string
问题描述
你好,我有这个文本文件的输出:
c:\ test.txt)
_Interface:192.155。 2.27 --- 0xb
_互联网地址物理地址类型
_192.154.244.255 45-44-44-44-bc-44动态
_192.154.43.55 ff-ff-ff-ff-ff-ff static
_224.0.0.22 01-00-5e-44-00-44 static
_224.0.0.251 01-44-44-00-00-44静态
_224.0.0.252 01-00-44-00-00-44静态
_239.255.255.250 01-44-5e-7f-ff-44 static
_255.255.255.255 ff-ff-ff-ff-ff-ff static
我如何只选择
Hello, I have an output for this text file:
c:\test.txt")
_Interface: 192.155.2.27 --- 0xb
_Internet Address Physical Address Type
_192.154.244.255 45-44-44-44-bc-44 dynamic
_192.154.43.55 ff-ff-ff-ff-ff-ff static
_224.0.0.22 01-00-5e-44-00-44 static
_224.0.0.251 01-44-44-00-00-44 static
_224.0.0.252 01-00-44-00-00-44 static
_239.255.255.250 01-44-5e-7f-ff-44 static
_255.255.255.255 ff-ff-ff-ff-ff-ff static
How can I select only
192.154.244.255
并忽略前面的空格。
我尝试了什么:
到目前为止我有这个:
Dim lines = System.IO.File.ReadAllLines(c:\ test.txt)
Dim line3 As String = lines(3)
Dim source As String = lines(3)
Dim cutdown As String = source.Substring(2,15)
MessageBox.Show(减少)
这是通过删除开头的空间并计算
第3行的长度并选择ip 192.154.244.255。问题是ip可以少于12位数,所以计数程序不起作用。
谢谢。
and also ignore the space in the front.
What I have tried:
So far I have this:
Dim lines = System.IO.File.ReadAllLines("c:\test.txt")
Dim line3 As String = lines(3)
Dim source As String = lines(3)
Dim cutdown As String = source.Substring(2, 15)
MessageBox.Show(cutdown)
This is working by removing the space at the beginning and counts the length of
line 3 and selects the ip 192.154.244.255. The problem is the ip can have less than 12 digits so the counting procedure would not work.
Thank you.
推荐答案
使用正则表达式。请参阅 vb.net - Regex for IP(v4)地址 - 堆栈溢出 [ ^ ]。
Use a regular expression. See vb.net - Regex for IP (v4) address - Stack Overflow[^].
这篇关于如何从文本文件第二行中选择第一个字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!