您的位置:程序门 -> vb -> 基础类



新手求助:如何用vb修改txt文件


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


新手求助:如何用vb修改txt文件
发表于:2007-03-30 09:54:03 楼主
如何用vb修改txt文件
那位大哥帮我一把,我需要用vb修改指定txt文件中的固定位置的数据.比如我要不把

"12   35   3243   32434   34     4343343   787  
45454   656   5   7676   878     98989   4534 "

中第二行中的878改为   999,

该用什么方法,谢谢了

发表于:2007-03-30 10:22:401楼 得分:0
请把下面代码放入一个按钮下试验一下

        '把文本文件装入一个数组,每行为一个数组元素
        open   app.path   &   "\test.txt "   for   input   as   #1
        dim   strarray()   as   string
        dim   i   as   long
        i   =   0
        dim   strline   as   string
        do   while   not   eof(1)       '   循环至文件尾。
                input   #1,   strline
                redim   preserve   strarray(i)
                strarray(i)   =   strline
                i   =   i   +   1
        loop
        close   #1
       
        '替换第二行的878
        strarray(1)   =   replace(strarray(1),   "878 ",   "999 ")
       
        '重写回test.txt文件
        open   app.path   &   "\test.txt "   for   output   as   #1
        dim   j   as   long
        for   j   =   0   to   i   -   1
                print   #1,   strarray(j)
        next
        close   #1
发表于:2007-03-30 10:31:152楼 得分:0
补充:
我把
12   35   3243   32434   34     4343343   787  
45454   656   5   7676   878     98989   4534
放入项目目录下的test.txt文件了


快速检索

最新资讯
热门点击