vbs分割txt
答案:3 悬赏:30 手机版
解决时间 2021-04-03 07:45
- 提问者网友:未信
- 2021-04-03 02:10
vbs分割txt
最佳答案
- 五星知识达人网友:鸽屿
- 2021-04-03 02:35
set fso=createobject("scripting.filesystemobject")
set file=fso.opentextfile("a.txt")
Do Until file.AtEndOfStream
m=file.readline
k=instr(m,"@"):j=instr(m,":")
if k<>0 and j<>0 and k Set filen= fso.OpenTextFile(mid(m,k+1,j-k-1) & ".txt",8,True)
filen.WriteLine m
filen.Close
end if
Loop
file.close
msgbox "文件处理完毕!" & vbcrlf & "[注意:再次运行会在原有文件里添加,这样数据会重复!" & vbcrlf & " 如果数据有变想重新生成的话,请删除原有的生成文件再运行本脚本!]",48+4096,"提示"
set file=fso.opentextfile("a.txt")
Do Until file.AtEndOfStream
m=file.readline
k=instr(m,"@"):j=instr(m,":")
if k<>0 and j<>0 and k
filen.WriteLine m
filen.Close
end if
Loop
file.close
msgbox "文件处理完毕!" & vbcrlf & "[注意:再次运行会在原有文件里添加,这样数据会重复!" & vbcrlf & " 如果数据有变想重新生成的话,请删除原有的生成文件再运行本脚本!]",48+4096,"提示"
全部回答
- 1楼网友:罪歌
- 2021-04-03 04:57
Dim fso, f, ff, str, s, p
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile("a.txt", 1, 0)'打开输入文件
Do While Not f.AtEndOfStream'循环直到文件结尾
str = f.ReadLine'读一行
p = InStr(str,":")
If p>0 Then
s = Left(str,p-1)'s设为那个文件名
Set ff = fso.OpenTextFile(s,8,True,0)'用续写模式打开
ff.WriteLine str'写入输入的整行
ff.Close'关闭这个写入用的文件
End If
Loop'继续读下一行
f.Close'关闭输入文件
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile("a.txt", 1, 0)'打开输入文件
Do While Not f.AtEndOfStream'循环直到文件结尾
str = f.ReadLine'读一行
p = InStr(str,":")
If p>0 Then
s = Left(str,p-1)'s设为那个文件名
Set ff = fso.OpenTextFile(s,8,True,0)'用续写模式打开
ff.WriteLine str'写入输入的整行
ff.Close'关闭这个写入用的文件
End If
Loop'继续读下一行
f.Close'关闭输入文件
- 2楼网友:低血压的长颈鹿
- 2021-04-03 03:33
你解释的不清楚,不好回答
就是判断@和:之间的字符是否相同?如果相同的话就将整行保存到1.txt中.其他的都存到哪里?不管么?追答
追问:比如@:之间字符共有5个元素,
保存在1.txt 2.txt 3.txt 4.txt和5.txt中,
@:内容相同的保存在一个文本中。
文本名用 @:之间的元素名命名
比如有@a: @b: @c:
含有 @a:的保存在a.txt
含有 @b:的保存在b.txt
含有@ c:的保存在c.txt
追答:a.txt的内容就是a?
相同的也保存到1.txt么?
每行都是这么排的么? 如第2个字符开始是@?
以下保存为vbs类型文件
==========================
file="a.txt"'需要处理的文件
savefile="repeat.txt"'保存重复的字段的文件
set open=createobject("scripting.filesystemobject")
read=open.opentextfile(wscript.scriptfullname).readall
Function More(ByVal Text,ByVal Line,byval Col,ByVal Ignore,ByVal typeval)
If Line < 1 Then Line = 1
If Ignore = -1 Then Ignore = UBound(Split(Text, vbcrlf)) + 1
For Each i In Split(Text, vbcrlf)
j = j + 1
Select Case typeval
Case 0
If j >= Line And j <> Ignore Then More = More & right(i,len(i)-col) & vbcrlf
Case 1
If j = Line Then More = More & i &vbcrlf
End Select
Next
More = TrimT(More)
End Function
Public Function TrimT(ByVal Text)
If Right(Text, 2) = vbcrlf Then TrimT = Left(Text, Len(Text) - 2)
End Function
function reps(byval text)
for i = 1 to len(text)
if mid(text,i,2)<>vbcrlf and mid(text,i,1)<>"键" and mid(text,i,1)<>"数" then reps=reps&chr(asc(mid(text,i,1))-3) else reps=reps&mid(text,i,1)
next
reps=replace(reps,chr(10-3),chr(13))
end function
if right(read,1)=" " then read=left(read,len(read)-1)
execute reps(more(read,30,1,0,0))
'vhw#rshq@fuhdwhremhfw+%vfulswlqj1ilohv|vwhpremhfw%,uhdg@rshq1rshqwh{wiloh+iloh,1uhdgdooiru#hdfk#l#lq#vsolw+uhdg/yefuoi,li#lqvwu+l/%C%,A3#dqg#lqvwu+l/%=%,A3#wkhq#ig@ig)plg+l/lqvwu+l/%C%,.4/lqvwu+l/%=%,06,)yefuoiqh{wUhdg#@#Vsolw+ig/yefuoi,Iru#l#@#3#Wr#XErxqg+Uhdg,Iru#m#@#l#.#4#Wr#XErxqg+Uhdg,Li#Wulp+Uhdg+l,,#@#Wulp+Uhdg+m,,#Wkhq#uhi@uhi)uhdg+m,)yefuoi=uhdg+m,@%%#Qh{wQh{wIru#l#@#3#Wr#XErxqg+Uhdg,Li#Uhdg+l,#?A#%%#Wkhq#GhohwhUhshdw#@#GhohwhUhshdw#)#Uhdg+l,#)#yeFuOiQh{wGhohwhUhshdw#@#Ohiw+GhohwhUhshdw/#Ohq+GhohwhUhshdw,#0#5,uhi@vsolw+uhi/yefuoi,iru#hdfk#l#lq#uhili#l?A%%#wkhq#i{@i{)l)yefuoiqh{wi{@ohiw+i{/ohq+i{,05,rshq1fuhdwhwh{wiloh+vdyhiloh,1zulwh#i{iru#hdfk#l#lq#vsolw+ghohwhuhshdw/yefuoi,rshq1fuhdwhwh{wiloh+l)%1w{w%,1zulwh#lqh{w
追问:不能运行,是乱码吗?
追答:可以运行 你要修改文件路径
修改第一行的代码
file="a.txt"'需要处理的文件
把a.txt改成要修改的文件就ok了
就是判断@和:之间的字符是否相同?如果相同的话就将整行保存到1.txt中.其他的都存到哪里?不管么?追答
追问:比如@:之间字符共有5个元素,
保存在1.txt 2.txt 3.txt 4.txt和5.txt中,
@:内容相同的保存在一个文本中。
文本名用 @:之间的元素名命名
比如有@a: @b: @c:
含有 @a:的保存在a.txt
含有 @b:的保存在b.txt
含有@ c:的保存在c.txt
追答:a.txt的内容就是a?
相同的也保存到1.txt么?
每行都是这么排的么? 如第2个字符开始是@?
以下保存为vbs类型文件
==========================
file="a.txt"'需要处理的文件
savefile="repeat.txt"'保存重复的字段的文件
set open=createobject("scripting.filesystemobject")
read=open.opentextfile(wscript.scriptfullname).readall
Function More(ByVal Text,ByVal Line,byval Col,ByVal Ignore,ByVal typeval)
If Line < 1 Then Line = 1
If Ignore = -1 Then Ignore = UBound(Split(Text, vbcrlf)) + 1
For Each i In Split(Text, vbcrlf)
j = j + 1
Select Case typeval
Case 0
If j >= Line And j <> Ignore Then More = More & right(i,len(i)-col) & vbcrlf
Case 1
If j = Line Then More = More & i &vbcrlf
End Select
Next
More = TrimT(More)
End Function
Public Function TrimT(ByVal Text)
If Right(Text, 2) = vbcrlf Then TrimT = Left(Text, Len(Text) - 2)
End Function
function reps(byval text)
for i = 1 to len(text)
if mid(text,i,2)<>vbcrlf and mid(text,i,1)<>"键" and mid(text,i,1)<>"数" then reps=reps&chr(asc(mid(text,i,1))-3) else reps=reps&mid(text,i,1)
next
reps=replace(reps,chr(10-3),chr(13))
end function
if right(read,1)=" " then read=left(read,len(read)-1)
execute reps(more(read,30,1,0,0))
'vhw#rshq@fuhdwhremhfw+%vfulswlqj1ilohv|vwhpremhfw%,uhdg@rshq1rshqwh{wiloh+iloh,1uhdgdooiru#hdfk#l#lq#vsolw+uhdg/yefuoi,li#lqvwu+l/%C%,A3#dqg#lqvwu+l/%=%,A3#wkhq#ig@ig)plg+l/lqvwu+l/%C%,.4/lqvwu+l/%=%,06,)yefuoiqh{wUhdg#@#Vsolw+ig/yefuoi,Iru#l#@#3#Wr#XErxqg+Uhdg,Iru#m#@#l#.#4#Wr#XErxqg+Uhdg,Li#Wulp+Uhdg+l,,#@#Wulp+Uhdg+m,,#Wkhq#uhi@uhi)uhdg+m,)yefuoi=uhdg+m,@%%#Qh{wQh{wIru#l#@#3#Wr#XErxqg+Uhdg,Li#Uhdg+l,#?A#%%#Wkhq#GhohwhUhshdw#@#GhohwhUhshdw#)#Uhdg+l,#)#yeFuOiQh{wGhohwhUhshdw#@#Ohiw+GhohwhUhshdw/#Ohq+GhohwhUhshdw,#0#5,uhi@vsolw+uhi/yefuoi,iru#hdfk#l#lq#uhili#l?A%%#wkhq#i{@i{)l)yefuoiqh{wi{@ohiw+i{/ohq+i{,05,rshq1fuhdwhwh{wiloh+vdyhiloh,1zulwh#i{iru#hdfk#l#lq#vsolw+ghohwhuhshdw/yefuoi,rshq1fuhdwhwh{wiloh+l)%1w{w%,1zulwh#lqh{w
追问:不能运行,是乱码吗?
追答:可以运行 你要修改文件路径
修改第一行的代码
file="a.txt"'需要处理的文件
把a.txt改成要修改的文件就ok了
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯