|
- Function TxtReadLines(txtPath,delimiter)
- Dim objDictionary,objFso,objTxtFile
- Dim strReadLine,splitReadLine
- Dim lineCount
- Set objDictionary=CreateObject("Scripting.Dictionary")
- Set objFso=CreateObject("Scripting.FileSystemObject")
- Set objTxtFile=objFso.OpenTextFile(txtPath,1,true)
- Do while not(objTxtFile.AtEndOfStream)
- strReadLine=objTxtFile.ReadLine
- objTxtFile.SkipLine
- If instr(strReadLine,delimiter)>0 Then
- lineCount=lineCount+1
- splitReadLine=split(strReadLine,delimiter)
- objDictionary.Add "left"&cstr(lineCount),trim(splitReadLine(0))
- objDictionary.Add "right"&cstr(lineCount),trim(splitReadLine(1))
- End If
- loop
- Set objTxtFile=nothing
- Set objFso=nothing
- Set TxtReadLines=objDictionary
- Set objDictionary=nothing
- End Function
- '传递文件的路径和分隔符,比如你说的等号
- Set txtDic=TxtReadLines("d:\text.txt","=")
- For i=1 to txtDic.count/2
- '等号左边的值
- msgbox txtDic.Item("left"&cstr(i))
- '等号右边的值
- msgbox txtDic.Item("right"&cstr(i))
- Next
复制代码 |
|