我想从文本文件中提取一些信息。这是我的文本文件中的一行,我想提取数字并将这些数字保存在一个数组中。
ST/X   1000.0000000000000000   1400.0000000000000000   40.0000000000000000   25.0000000000000000   12.0000000000000000  
数字的数量不固定(即在这个例子中我有 5 个数字,但它可能或多或少)数字之间总是有 3 个空格,但数字的长度也不是固定的(例如 1000.0000000000000000 的长度为21,但 12.0000000000000000 的长度为 19)。我写了这段代码。但我的代码的问题是它也将空格作为最后一个数字返回。我的代码不能正常工作你有更好的想法让我更好地完成这项工作吗?谢谢你的帮助和想法:)
我的代码:
 Dim lngPos As Long 
 Dim lngCount As Long 
 Dim ifile As Integer 
 Dim Xarray() As String 
 Let ifile = FreeFile 
 Dim Name As String 
 Dim xi As Integer 
 Name = util1.fDateiName("*.txt", "Text") 
'"C:\Dokumente und Einstellungen\bbastan\Desktop\test.txt" 
'Open Name For Input As ifile 
'While Not EOF(ifile) 
'Line Input #ifile, entireline 
ReDim Xarray(10) 
xi = 0 
Open Name For Input As ifile 
lngPos = 1 
While Not EOF(ifile) 
Line Input #ifile, entireline 
       Do 
        lngPos = InStr(lngPos, entireline, Space(3)) 
        If lngPos > 0 Then 
            xi = xi + 1 
            lngCount = lngCount + 1 
            lngPos = lngPos + 3 
            Xarray(xi) = Mid(entireline, lngPos, 21) 
        End If 
    Loop Until lngPos = 0 
Wend 
Dim I As Integer 
If xi > 2 Then 
MsgBox "ja" 
For I = 1 To xi - 1 
MsgBox Xarray(I) 
Next I 
Else 
MsgBox "nein" 
For I = 1 To xi 
MsgBox Xarray(I) 
Next I