VB中删除、替换或者插入内容到文本中某一行,及文本行列的处理实例[2]

[入库:2005年8月18日] [更新:2007年3月24日]

本文简介:选择自 soho_andy 的 blog

        filecontents = space(lof(filenum))
        get #filenum, , filecontents
    close filenum
    fileinfo = split(filecontents, vbcrlf)
    '取出源文件行数,按照回车换行来分隔成数组
   
    filenum = freefile
    tmpdemdata = ""
    if dir(strtargetfile, vbnormal) <> "" then
        kill strtargetfile
    end if
    dim filestr() as string

    open strtargetfile for append as #filenum
        '循环每一行
        for i = 0 to ubound(fileinfo) - 1
            filestr = split(trim(fileinfo(i)), ",")  '按照逗号分隔每一行的数据
            tmpdemdata = ""
            for j = 0 to ubound(filestr)
                '判断是否为奇数位
                if (j mod 2) = 0 then
                    tmpdemdata = tmpdemdata & filestr(j)
                elseif j <> 0 and j <> ubound(filestr) then
                    tmpdemdata = tmpdemdata & ","
                end if
            next
            '保存一行如目标文件
            print #filenum, tmpdemdata
        next
    close #filenum
    msgbox "完毕"
end sub

private sub command1_click()
    提取奇数位数据 "d:\aa.txt", "d:\bb.txt"

本文关键:VB 删除 替换 插入 行列
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top