Var1 = InputBox("搜索内容")
Set re = New RegExp
re.Pattern = Var1 + "\r\n(.*\r\n)
re.Global = -1
Set f = CreateObject("Scripting.FileSystemObject").OpenTextFile("C:\123.txt")
c = f.ReadAll()
c = re.Replace(c, "")
f.Close()
CreateObject("Scripting.FileSystemObject").OpenTextFile("C:\123.txt", 2).Write c
4,C 编程 删除文本文件特定内容
首先要引用一个命名空间
using System.IO;
代码如下:
string str = File.ReadAllText("D:\\a.txt");//读出a.txt的文本内容
int i=str.IndexOf("am");//找到am的位置
str = str.Substring(i,str.Length-i);//删掉am前面的内容
i=str.LastIndexOf("a");//找到第二个a的位置
str = str.Substring(0,i+1);//删除第二个a后面的内容
File.WriteAllText("D:\\a.txt",str);//把分割后的文本写入到a.txt中你还可以使用string的replace的方法替换,将你想要删除的字符串替换成一个空的字符串读成字符串
正则表达式替换
保存回去