• 软件测试技术
  • 软件测试博客
  • 软件测试视频
  • 开源软件测试技术
  • 软件测试论坛
  • 软件测试沙龙
  • 软件测试资料下载
  • 软件测试杂志
  • 软件测试人才招聘
    暂时没有公告

字号: | 推荐给好友 上一篇 | 下一篇

VB学习:文本插入与编辑处理实例

发布: 2007-6-21 21:57 | 作者: SoHo_Andy  | 来源: CSDN  | 查看: 17次 | 进入软件测试论坛讨论

领测软件测试网

下一页 1 2 3 

   

  VB操作文本文件的方法很多,下面的例子是我自己作项目或者回答网友提问时做的,很有代表性,希望能够给各位朋友一些启发.

  '功能:删除、替换文本中一行,或者插入内容到文本中某一行
  '作者: soho_andy (冰)
  '参数:
  'strSourceFile  原始文件完整名
  'strTargetFile  生成新文件的完整名
  'intRow         操作的行数

  Sub 操作文件中一行(strSourceFile As String, strTargetFile As String, intRow As Long)
    Dim filenum         As Integer
    Dim fileContents    As String
    Dim fileInfo()      As String
    Dim i               As Integer
    Dim j               As Integer
   
    filenum = FreeFile
    Open strSourceFile For Binary As #filenum
        fileContents = Space(LOF(filenum))
        Get #filenum, , fileContents
    Close filenum
    fileInfo = Split(fileContents, vbCrLf)
    '取出源文件行数,按照回车换行来分隔成数组
   
    filenum = FreeFile
    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
            If i <> intRow - 1 Then
                Print #filenum, fileInfo(i)
            End If
        Next
    Close #filenum
   

文章来源于领测软件测试网 https://www.ltesting.net/


关于领测软件测试网 | 领测软件测试网合作伙伴 | 广告服务 | 投稿指南 | 联系我们 | 网站地图 | 友情链接
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备10010545号-5
技术支持和业务联系:info@testage.com.cn 电话:010-51297073

软件测试 | 领测国际ISTQBISTQB官网TMMiTMMi认证国际软件测试工程师认证领测软件测试网