标题: [问题求助] 【已解决】VBS文本数据按列合并,如何才能不乱序 [打印本页]
作者: 思想之翼 时间: 2022-5-24 07:47 标题: 【已解决】VBS文本数据按列合并,如何才能不乱序
本帖最后由 思想之翼 于 2023-3-3 14:38 编辑
有三个文本,数据格式为:
001.txt
11
002.txt
22
22
003.txt
33
33
33
欲按列合并成一个文本,格式如下所示:
11 22 33
22 33
33
下示VBS代码合并文本数据后,打乱了各列的顺序:
11 22 33
22 33
33
如何修正?- On Error Resume Next
- fileNum = 3
- Max =0 : ReDim ar(fileNum)
- Set fso = CreateObject("Scripting.FileSystemObject")
-
- For i = 1 to fileNum
- Set f = fso.OpenTextFile("d:\00\" & Right("00" & i, 3) & ""& ".txt")
- ar(i) = Split(RegEx(f.ReadAll), vbCrLf)
- If UBound(ar(i)) > Max Then Max = UBound(ar(i))
- f.Close : Set f = Nothing
- Next
-
- For i = 0 to Max
- s = ""
- For j = 1 to fileNum
- s = s & " " & ar(j)(i)
- Next
- fso.OpenTextFile("d:\00\all.txt", 8, true).WriteLine Mid(s, 2)
- Next
-
- 'MsgBox "OK"
-
- Function RegEx(txt)
- Set re = New RegExp
- re.Pattern = "^(\s*\n)+|(\s*\n)+$"
- re.Global = true
- txt = re.Replace(txt, "")
- re.Pattern = "(\s*\n)+"
- RegEx = re.Replace(txt, vbCrLf)
- End Function
复制代码
欢迎光临 批处理之家 (http://bathome.net./) |
Powered by Discuz! 7.2 |