当前位置:编程学习 > VB >>

读取多个文件按行读取一个文件一行怎么不行能呢?

--------------------编程问答-------------------- Open a(fn) For Binary As #1
看看msdn中Open的帮助,for 的类型
--------------------编程问答-------------------- Open a(fn) For Input As #1 --------------------编程问答-------------------- Windows 下的换行符为 vbCrLf,而 Linux 下的换行符为 vbLf。
所以 Linux 下的 log 文件不能直接用 VB 的文本方式读取,应该先用 vim 之类的工具将换行符 \n 替换为 \r\n,再到 Windows 下使用。 --------------------编程问答--------------------
dim sBuff as string,sLBuff() as string
dim I as long
 
open "xx.log" for binary as #1
    sbuff=space(lof(1))
    get #1,,sbuff
close #1
 
slbuff()=split(sbuff,vbcr)        '这里先要确定log文件的换行符,就可以按行拆分了
for i=0 to ubound(slbuff)
    slbuff(I)=trim(slbuff(I))
    if slbuff(I)<>"" then
        debug.print slbuff(I)
    end if
next

一次性读入吧,速度快些.

不过需要先确定好换行符是什么. --------------------编程问答-------------------- 请问这句什么意思sbuff=space(lof(1))??? --------------------编程问答-------------------- 在linux下执行下 unix2dos xxx.txt 然后再拿过来执行看看。
补充:VB ,  基础类
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,