我想读取字符串中的某个值。每行是一个新的字符串,我想读取每行上的第6个整数。VB.net与子字符串拆分功能
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles browsebtn.Click
If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
Dim filename As String = OpenFileDialog1.FileName
Dim streamreader As New System.IO.StreamReader(filename)
Dim textfile As String = streamreader.ReadToEnd
Dim splitChar As String = vbNewLine
Dim day As Integer = textfile.Substring(10, 2)
Dim strLine() As String = day.Split(splitChar)
For Each line As String In strLine
MsgBox(day)
Next
End If
End Sub
End Class
但它只返回一个数字。如果我将day设置为一个字符串而不是一个整数,它将完美工作,除了它读取整个字符串,而不是我需要的两个整数。请帮忙。我究竟做错了什么?
编辑:
输入文件看起来是这样的:
23728 121010 00004986 00 00 2 21 22 11 447 114 2 382 292 350
23730 121010 00064120 00 00 51 19 21 12 1064 110 2 4500 572 7734
我希望我的输出是:
10
10
10来自于 “121010”
向我们显示输入(您的文本文件)和所需的输出?还请注意使用块 – qwr
我将其添加到我的问题中。谢谢 –
那么,你如何确定“10”开始和结束的位置?这是第六个整数? –