分享一個更簡單的方法...用WSH...
[步驟1]在C:\ 建立一個文字檔"data.txt",裡面的內容是...
caseD-1-00001
caseD-1-00001
caseD-1-00001
caseD-1-00001
===============
[步驟2]在C:\ 建立一個文字檔並命名為 "fixNum.vbs",裡面的內容是...
Set objRegEx = CreateObject("VBScript.RegExp")
Dim arrFileLines()
AAA = ""
i = 0
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\data.txt", 1)
Do Until objFile.AtEndOfStream
Redim Preserve arrFileLines(i)
arrFileLines(i) = objFile.ReadLine
i = i + 1
Loop
objFile.Close
'readfile finished!
Set objRegEx = CreateObject("VBScript.RegExp")
objRegEx.Global = True
objRegEx.IgnoreCase = True
objRegEx.Pattern = "\d{5}"
For l = LBound(arrFileLines) to UBound(arrFileLines) Step 1
strNewString = objRegEx.Replace(arrFileLines(l),"0000" & (l+1) )
AAA = AAA & strNewString & chr(10)
Next
Wscript.Echo AAA
==================
[步驟3]在DOS模式底下執行[步驟2]的fixNum.vbs即可~
例如: C:\fixNum.vbs [enter]
執行結果:
caseD-1-00001
caseD-1-00002
caseD-1-00003
caseD-1-00004
================
執行結果是用Echo出來的,也可以將它寫回文字檔...用VBSCRIPT的語法~分享~
|