标题: [问题求助] VBS怎样替换UTF-8格式文本内的内容? [打印本页]
作者: zhiyong_530 时间: 2011-7-5 10:48 标题: VBS怎样替换UTF-8格式文本内的内容?
- set fso=CreateObject("Scripting.FileSystemObject")
- set ws=CreateObject("wscript.shell")
- filename="123.txt"
- ansi2utf8 filename,"utf-8","gbk","temp.tmp"
- set fr=fso.opentextfile("temp.tmp",1,-1)
- set fw=fso.createtextfile("temp2.tmp",2)
- Set regEx = New RegExp
- do
- data=fr.readline
- regEx.Pattern = "<add key=""UseSecLCD"" value=""N"" />"
- data = regEx.Replace(data, "<add key=""UseSecLCD"" value=""Y"" />")
- fw.writeline data
- loop until fr.atendofstream
- fw.close:fr.close
- ansi2utf8 "temp2.tmp","gbk","utf-8",filename
- fso.deletefile "temp.tmp",true
- fso.deletefile "temp2.tmp",true
- function ansi2utf8(strFile,s1,s2,newname)
- Set ADOStrm = CreateObject("ADODB.Stream")
- ADOStrm.Type = 2
- ADOStrm.Mode = 3
- ADOStrm.CharSet = s1
- ADOStrm.Open
- ADOStrm.LoadFromFile strFile
- s = ADOStrm.ReadText
- ADOStrm.Position = 0
- ADOStrm.CharSet = s2
- ADOStrm.WriteText s
- ADOStrm.SetEOS
- ADOStrm.SaveToFile newname, 2
- ADOStrm.Close
- 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
- regEx.Pattern = "<add key=""UseSecLCD"" value=""N"" />"
-
- data = regEx.Replace(data, "<add key=""UseSecLCD"" value=""Y"" />")
复制代码
改这两句:- regEx.Pattern = "<add key=""SecondMonitorGridWidthSize"" value=""400"" />"
-
- data = regEx.Replace(data, "<add key=""SecondMonitorGridWidthSize"" value=""我是某值"" />")
复制代码
欢迎光临 批处理之家 (http://bathome.net./) |
Powered by Discuz! 7.2 |