小改一下,1-n位,试试- Set fso = CreateObject("Scripting.FileSystemObject")
- For i = 1 to 10
- Set file = fso.OpenTextFile(i & ".txt", 1)
- ReDim arRow(0) : str = ""
- while Not file.AtEndOfStream
- strLine = RegEx(file.ReadLine)
- If strLine <> "" Then
- arLine = Split(strLine, " ")
- ReDim Preserve arRow(UBound(arLine))
- For j = 0 to UBound(arLine)
- arRow(j) = arRow(j) & " " & arLine(j)
- Next
- End If
- wend
- For j = 0 to UBound(arRow)
- str = str & " " & GetNum(arRow(j))
- Next
- fso.OpenTextFile("New" & i & ".txt", 2, true).Write Mid(str, 2)
- Next
-
- MsgBox "OK"
-
- Function RegEx(strLine)
- Set re = New RegExp
- re.Global = true
- re.Pattern = "\s+"
- RegEx = Trim(re.Replace(strLine," "))
- End Function
-
- Function GetNum(s)
- ar = Split(s, " ")
- n = Len(ar(1)) : x = String(n,"0") ''n为数值位数,x为补零个数
- Set re = New RegExp
- re.Global = true
- re.Pattern = "(\d{" & n & "}) " & ar(1)
- For Each m in re.Execute(s)
- Num = Num + ar(1) - m.SubMatches(0)
- Next
- Num = Num + ar(1)
- If Num < 0 Then
- GetNum = Right(x & (10^n - Right(x & Abs(Num), n)), n)
- Else GetNum = Right(x & Num, n)
- End If
- End Function
复制代码
|