"Chris Hohmann" wrote in message
news:Or******** ******@tk2msftn gp13.phx.gbl...
: "Roland Hall" <nobody@nowhere > wrote in message
: news:Ol******** ******@TK2MSFTN GP15.phx.gbl...
: > I have a little test that replaces the same character with two different
: > values. Currently I have to process it twice. Is it possible to do it
: all
: > at once?
: >
: > dim a, z
: > a = "a,b,c"
: > z = replace(a,","," x",1,1)
: > Response.write( replace(z,","," y"))
: >
: > I'm thinking regular expressions are the way to go but in use it will
have
: > to replace a single character with an XML tag.
:
: <script language="Javas cript" runat="SERVER">
: Response.Write( "a,b,c".replace (/,([^,]*),/,"x$1y"));
: </script>
:
: <script language="VBScr ipt" runat="SERVER">
: Dim re
: Set re = New RegExp
: re.Pattern=",([^,]*),"
: Response.Write re.Replace("a,b ,c","x$1y")
: Set re = Nothing
: </script>
Thanks Chris. That's the information I needed.
I saw that I could expand on that and add more substitutions. I'm using
array elements as variables to shorten the line and allow for additional
substitutions because I will eventually use this with 13. Currently I
haven't attempted that yet but I have worked out the code for 3 so
additional ones are no problem.
This was my first success based upon your regular expression.
sub processXML (str, n)
dim arr, i, arr2(), j, text, strText
dim re
set re = new regexp
with re
.Global = True
.Pattern = ",([^,]*),"
end with
dim arrXML(4)
arrXML(0) = "<rgp><doma in>"
arrXML(1) = "</domain><entryda te>"
arrXML(2) = "</entrydate><dele tedate>"
arrXML(3) = "</deletedate></rgp>"
arrXML(4) = "</domain><deleted ate>"
arr = split(str,vbLf)
j = 0
redim arr2(ubound(arr ))
for i = 0 to ubound(arr2)
select case i
case 0 :
arr2(j) = "<reportdat e>" & arr(i) & "</reportdate>" & vbLf
j = j + 1
case 1 :
case else :
select case n
case 1 :
if arr(i) <> "" then arr2(j) = arrXML(0) & re.Replace(arr( i),arrXML(1)
& "$1" & arrXML(2)) & arrXML(3) & vbLf
j = j + 1
case 2 :
if arr(i) <> "" then arr2(j) = arrXML(0) &
Replace(arr(i), ",",arrXML( 4)) & arrXML(3) & vbLf
j = j + 1
case else
end select
end select
next
text = join(arr2) & "</root>" & vbLf
strText = "<?xml version='1.0' encoding='ISO-8859-1'?>" & vbLf
strText = strText & "<root>" & vbLf & text
writeFile(strTe xt)
end sub
--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center -
http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation -
http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library -
http://msdn.microsoft.com/library/default.asp