[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖
  1. Dim strFile: strFile = "urfile"
  2. Dim FSO:     Set FSO = CreateObject("Scripting.FileSystemObject")
  3. Dim objFile: Set objFile = FSO.OpenTextFile(strFile)
  4. Dim strContent: strContent = objFile.Readall
  5. objFile.Close
  6. strContent = RegExp(strContent, ",", chr(124))
  7. strContent = RegExp(strContent, "([\d])[|]([\d])", "$1" & chr(44) & "$2")
  8. Function RegExp(str1, patrn, replStr)
  9.   Dim regEx  
  10.   Set regEx = New RegExp
  11.   regEx.Pattern = patrn
  12.   regEx.IgnoreCase = True
  13.   regEx.Global = True
  14.   RegExp = regEx.Replace(str1, replStr)
  15. End Function
  16. Dim objTextFile: Set objTextFile = FSO.CreateTextFile("op.txt")
  17. objTextFile.Write strContent
  18. Wscript.Quit
复制代码

[ 本帖最后由 asnahu 于 2011-1-28 15:55 编辑 ]

TOP

打开文件全部读取并赋予变量strContent,然后对strContent进行正则替换:将全部“,”替换成“|”,将数字之间的“|”替换回来。

TOP

  1. strContent = RegExp(strContent, "([\d])[|]([\d])", "$1" & chr(44) & "$2")
复制代码

改为:
  1. strContent = RegExp(strContent, chr(34) & "(.*)[|](.*)" & chr(34) , chr(34) & "$1,$2" & chr(34))
复制代码

TOP

返回列表