replace text

R

Roland Hall

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.

TIA...

--
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
 
C

Chris Hohmann

Roland Hall said:
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="Javascript" runat="SERVER">
Response.Write("a,b,c".replace(/,([^,]*),/,"x$1y"));
</script>

<script language="VBScript" runat="SERVER">
Dim re
Set re = New RegExp
re.Pattern=",([^,]*),"
Response.Write re.Replace("a,b,c","x$1y")
Set re = Nothing
</script>
 
R

Roland Hall

in message
: : > 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="Javascript" runat="SERVER">
: Response.Write("a,b,c".replace(/,([^,]*),/,"x$1y"));
: </script>
:
: <script language="VBScript" 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><domain>"
arrXML(1) = "</domain><entrydate>"
arrXML(2) = "</entrydate><deletedate>"
arrXML(3) = "</deletedate></rgp>"
arrXML(4) = "</domain><deletedate>"
arr = split(str,vbLf)
j = 0
redim arr2(ubound(arr))
for i = 0 to ubound(arr2)
select case i
case 0 :
arr2(j) = "<reportdate>" & 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(strText)
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

ASP design question 4
VBScript function returning multiple values 17
Compressed Zipped Folder 6
Application question 2
the perfect function 4
screen scraping 4
Objects and collections 4
sub or function 26

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top