我有如下文本文件:
5-09-11 1:00 25.6 25.6 25.1 49 14.1 0.0 --- 0.00 0.0 --- 25.6
05-09-11 10:00 26.6 26.7 26.4 66 19.7 0.0 S 0.00 0.4 S 26.6
5-09-11 11:00 27.2 27.2 26.6 63 19.5 0.0 --- 0.00 0.0 --- 27.2
想要读取每个子段的内容进行分析,不知如何把它读到变量中,请大家帮忙?
5-09-11 1:00 25.6 25.6 25.1 49 14.1 0.0 --- 0.00 0.0 --- 25.6
05-09-11 10:00 26.6 26.7 26.4 66 19.7 0.0 S 0.00 0.4 S 26.6
5-09-11 11:00 27.2 27.2 26.6 63 19.5 0.0 --- 0.00 0.0 --- 27.2
想要读取每个子段的内容进行分析,不知如何把它读到变量中,请大家帮忙?
Dim astr() As String
Dim i as Long
Open "c:\tmp.txt" For Input As 1
str1 = Strconv(InputB$(LOF(1), 1), vbUnicode)
astr = split(str1 , vbCrLf)
For i=0 To Ubound(astr)
strLine=astr(i)
'strLine为一行的字符串
Next
dim arTmp() as String
nFile = FreeFile
Open 文本文件全路径名 For Input As #nFile
Do While Not EOF(nFile)
Line Input #nFile, strTmp
arTmp=Split(strTmp,分隔符) '不知道你分隔符是空格还是TAB?
分析该数组(arTmp(0)对应第一个字段,依次类推)
Loop
Close #nFile
Dim str1 As String
Dim astr1() As String,astr2() As String
Dim i as Long
Open "c:\tmp.txt" For Input As 1
str1 = Strconv(InputB$(LOF(1), 1), vbUnicode)
astr1 = split(str1 , vbCrLf)'以回车换行符分割
For i=0 To Ubound(astr1)
strLine=astr1(i)
'strLine为一行的字符串
'多个空格替换为一个
while not instr(strLine," ")=0
strLine=replace(strLine," "," ")
astr2=split(str1 , " ")
'遍历astr2得到
wend
Next
astr2=split(str1 , " ")
应该放在循环外面
dim arr() as string
open "c:\txtfile.txt" for input as #1
line input #1,str
arr=split(str," ")
....'处理过程close #1
while not instr(strLine," ")=0
strLine=replace(strLine," "," ")
astr2=split(str1 , " ")
'遍历astr2得到
wend