aa,dd,dd,gg,hh,ttt,2
dd,t,t,h,ffdf,2df,r
ddl,dfgfg,d,g,tt,ttt,w
......
先向将该文件夹下的所有文本文件进行处理,得到:
dd,t,t,h,ffdf,2df,r
......
即判断每行第五个逗号后的数据,若为ttt便将正行数据都删除,删除后的文本重新命名保存。
望高手指点,谢谢!
6 个解决方案
#1
逐行读取,比较,不符合写入新文件即可
#2
大概意思我明白,就是如何具体写,麻烦高手指点。
#3
1.检查并创建文件
2.利用ifnum = FreeFile() Open strFileName For Append As #ifnum打开两个文件
3.逐行读取,符合条件就写入新的文件
4.关闭文件对象
2.利用ifnum = FreeFile() Open strFileName For Append As #ifnum打开两个文件
3.逐行读取,符合条件就写入新的文件
4.关闭文件对象
#4
每个txt文件有多大?
#5
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
string s = @"aa,dd,dd,gg,hh,ttt,2
dd,t,t,h,ffdf,2df,r
ddl,dfgfg,d,g,tt,ttt,w";
Console.WriteLine("before:");
Console.WriteLine(s);
var result = s.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries)
.Where(x => x.Trim().Split(',')[5] != "ttt");
s = result.First();
result.Skip(1).ToList().ForEach(x => s += "\r\n" + x);
Console.WriteLine("after:");
Console.WriteLine(s);
}
}
}
before:
aa,dd,dd,gg,hh,ttt,2
dd,t,t,h,ffdf,2df,r
ddl,dfgfg,d,g,tt,ttt,w
after:
dd,t,t,h,ffdf,2df,r
Press any key to continue . . .
#6
'此代码由“
正则测试工具 v1.1.34”自动生成,请直接调用TestReg过程
'此代码由“正则测试工具 v1.1.34”自动生成,请直接调用TestReg过程
Private Sub TestReg()
Dim strData As String
Dim reg As Object
strData = "aa,dd,dd,gg,hh,ttt,2" & vbCrLf & _
"dd,t,t,h,ffdf,2df,r" & vbCrLf & _
"ddl,dfgfg,d,g,tt,ttt,w" & vbCrLf
Set reg = CreateObject("vbscript.regExp")
reg.Global = True
reg.MultiLine = True
reg.Pattern = "^.*?,.*?,.*?,.*?,.*?,ttt,.*$\r\n"
Debug.Print reg.Replace(strData, "")
End Sub
#1
逐行读取,比较,不符合写入新文件即可
#2
大概意思我明白,就是如何具体写,麻烦高手指点。
#3
1.检查并创建文件
2.利用ifnum = FreeFile() Open strFileName For Append As #ifnum打开两个文件
3.逐行读取,符合条件就写入新的文件
4.关闭文件对象
2.利用ifnum = FreeFile() Open strFileName For Append As #ifnum打开两个文件
3.逐行读取,符合条件就写入新的文件
4.关闭文件对象
#4
每个txt文件有多大?
#5
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
string s = @"aa,dd,dd,gg,hh,ttt,2
dd,t,t,h,ffdf,2df,r
ddl,dfgfg,d,g,tt,ttt,w";
Console.WriteLine("before:");
Console.WriteLine(s);
var result = s.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries)
.Where(x => x.Trim().Split(',')[5] != "ttt");
s = result.First();
result.Skip(1).ToList().ForEach(x => s += "\r\n" + x);
Console.WriteLine("after:");
Console.WriteLine(s);
}
}
}
before:
aa,dd,dd,gg,hh,ttt,2
dd,t,t,h,ffdf,2df,r
ddl,dfgfg,d,g,tt,ttt,w
after:
dd,t,t,h,ffdf,2df,r
Press any key to continue . . .
#6
'此代码由“
正则测试工具 v1.1.34”自动生成,请直接调用TestReg过程
'此代码由“正则测试工具 v1.1.34”自动生成,请直接调用TestReg过程
Private Sub TestReg()
Dim strData As String
Dim reg As Object
strData = "aa,dd,dd,gg,hh,ttt,2" & vbCrLf & _
"dd,t,t,h,ffdf,2df,r" & vbCrLf & _
"ddl,dfgfg,d,g,tt,ttt,w" & vbCrLf
Set reg = CreateObject("vbscript.regExp")
reg.Global = True
reg.MultiLine = True
reg.Pattern = "^.*?,.*?,.*?,.*?,.*?,ttt,.*$\r\n"
Debug.Print reg.Replace(strData, "")
End Sub