Board logo

标题: [问题求助] VBS怎样替换UTF-8格式文本内的内容? [打印本页]

作者: zhiyong_530    时间: 2011-7-5 10:48     标题: VBS怎样替换UTF-8格式文本内的内容?

  1. set fso=CreateObject("Scripting.FileSystemObject")
  2. set ws=CreateObject("wscript.shell")
  3. filename="123.txt"
  4. ansi2utf8 filename,"utf-8","gbk","temp.tmp"
  5. set fr=fso.opentextfile("temp.tmp",1,-1)
  6. set fw=fso.createtextfile("temp2.tmp",2)
  7. Set regEx = New RegExp
  8. do
  9. data=fr.readline
  10. regEx.Pattern = "<add key=""UseSecLCD"" value=""N"" />"
  11. data = regEx.Replace(data, "<add key=""UseSecLCD"" value=""Y"" />")
  12. fw.writeline data
  13. loop until fr.atendofstream
  14. fw.close:fr.close
  15. ansi2utf8 "temp2.tmp","gbk","utf-8",filename
  16. fso.deletefile "temp.tmp",true
  17. fso.deletefile "temp2.tmp",true
  18. function ansi2utf8(strFile,s1,s2,newname)
  19. Set ADOStrm = CreateObject("ADODB.Stream")
  20. ADOStrm.Type = 2
  21. ADOStrm.Mode = 3
  22. ADOStrm.CharSet = s1
  23. ADOStrm.Open
  24. ADOStrm.LoadFromFile strFile
  25. s = ADOStrm.ReadText
  26. ADOStrm.Position = 0
  27. ADOStrm.CharSet = s2
  28. ADOStrm.WriteText s
  29. ADOStrm.SetEOS
  30. ADOStrm.SaveToFile newname, 2
  31. ADOStrm.Close
  32. end function
复制代码
这个是替换"<add key=""UseSecLCD"" value=""N"" 为"<add key=""UseSecLCD"" value=""Y"" 的
要是替换    <add key="SecondMonitorGridWidthSize" value="400" />   中的400为某一个值的时候,该怎么办呢?是更改条件regEx.Pattern = "<add key=""UseSecLCD"" value=""N"" />"
吗?是的话是怎样更改???


原文http://zhidao.baidu.com/question/246540943.html
作者: broly    时间: 2011-7-10 22:59

  1. regEx.Pattern = "<add key=""UseSecLCD"" value=""N"" />"
  2. data = regEx.Replace(data, "<add key=""UseSecLCD"" value=""Y"" />")
复制代码
改这两句:
  1. regEx.Pattern = "<add key=""SecondMonitorGridWidthSize"" value=""400"" />"
  2. data = regEx.Replace(data, "<add key=""SecondMonitorGridWidthSize"" value=""我是某值"" />")
复制代码





欢迎光临 批处理之家 (http://bbs.bathome.net/) Powered by Discuz! 7.2