vb操作html文本,VB操作文本文件的一个实例

be91cd4623ad8ba616b96ccecb783fcf.png

这是一个很有实际学习意义的VB操作文本文件的一个实例,学习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

\'替换一行代码块

Open strTargetFile For Append As #filenum

\'循环每一行

For i = 0 To UBound(fileInfo) - 1

If i = intRow - 1 Then

Print #filenum, \"你要替换进去的内容\"

End If Next

Close #filenum

\'插入一行代码块

Open strTargetFile For Append As #filenum

\'循环每一行

For i = 0 To UBound(fileInfo) - 1

If i = intRow - 1 Then

Print #filenum, \"你要插入到这行的内容\"

Print #filenum, fileInfo(i) \'保留原来的行,位置后移一位

End If

Next

Close #filenum

MsgBox \"完毕\"

End Sub

2829f2ca24f0d0090cbba57f30759f23.png

VB操作文本文件的一个实例.doc

下载Word文档到电脑,方便收藏和打印[全文共928字]

编辑推荐:

8b95f2eb3d3f7ce4dc3bf1178c74941e.png

8b95f2eb3d3f7ce4dc3bf1178c74941e.png

8b95f2eb3d3f7ce4dc3bf1178c74941e.png

下载Word文档

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值