vbs如何删除文本文件的行的函数

发布时间:2021-07-12 10:54:10 作者:chen
来源:亿速云 阅读:147

这篇文章主要介绍“vbs如何删除文本文件的行的函数”,在日常操作中,相信很多人在vbs如何删除文本文件的行的函数问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”vbs如何删除文本文件的行的函数”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!

Delete Line Function

复制代码 代码如下:


Function DeleteLine(strFile, strKey, LineNumber, CheckCase)
'DeleteLine Function by TomRiddle 2008

'Remove line(s) containing text (strKey) from text file (strFile)
'or
'Remove line number from text file (strFile)
'or
'Remove line number if containing text (strKey) from text file (strFile)

'Use strFile = "c:\file.txt" (Full path to text file)
'Use strKey = "John Doe" (Lines containing this text string to be deleted)
'Use strKey = "" (To not use keyword search)
'Use LineNumber = "1" (Enter specific line number to delete)
'Use LineNumber = "0" (To ignore line numbers)
'Use CheckCase = "1" (For case sensitive search )
'Use CheckCase = "0" (To ignore upper/lower case characters)


Const ForReading=1:Const ForWriting=2
Dim objFSO,objFile,Count,strLine,strLineCase,strNewFile
Set objFSO=CreateObject("Scripting.FileSystemObject")
Set objFile=objFSO.OpenTextFile(strFile,ForReading)
Do Until objFile.AtEndOfStream
strLine=objFile.Readline
If CheckCase=0 then strLineCase=ucase(strLine):strKey=ucase(strKey)
If LineNumber=objFile.Line-1 or LineNumber=0 then
If instr(strLine,strKey) or instr(strLineCase,strkey) or strKey="" then
strNewFile=strNewFile
Else
strNewFile=strNewFile&strLine&vbcrlf
End If
Else
strNewFile=strNewFile&strLine&vbcrlf
End If
Loop
objFile.Close
Set objFSO=CreateObject("Scripting.FileSystemObject")
Set objFile=objFSO.OpenTextFile(strFile,ForWriting)
objFile.Write strNewFile
objFile.Close

End Function


使用方法:
DeleteLine "c:\1.txt", "", 1, 0

到此,关于“vbs如何删除文本文件的行的函数”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注亿速云网站,小编会继续努力为大家带来更多实用的文章!

推荐阅读:
  1. Python删除n行后的其他行方法
  2. php删除文本文件中任意行的方法

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

vbs

上一篇:如何用bat批量创建文件夹

下一篇:Android中AlertDialog如何使用

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》