473,569 Members | 2,383 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

replace text

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
Jul 22 '05 #1
2 1645
"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>


Jul 22 '05 #2
"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
Jul 22 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
5654
by: Danny | last post by:
I need an asp command to strip out from a string all extra punctuation such as apostrophe, comma, period, spaces dashes, etc etc and just leave the letters. Can anybody give me some ideas? Thanks
3
4758
by: Miguel J. Jiménez | last post by:
Hi, I have the following node: <node> Some text here with lots of inside it... </node> and I would like it to transfrom it using XSLT to the following: Some text<br/> here with</br> lots of</br> inside it... Being <br/> HTML tags and not simple text like &lt;br/&gt;
5
21661
by: K.Simon | last post by:
Hello, it's very often neccessary to replace strings or a single character in my stylesheets. My solution looks awful and very long. Now i thought to solve this with an array like structure but i found no solution. The original code looks like the following: <!-- The replacement-function that i'm calling --> <xsl:template...
22
11092
by: Phlip | last post by:
C++ers: Here's an open ended STL question. What's the smarmiest most templated way to use <string>, <algorithms> etc. to turn this: " able search baker search charlie " into this: " able replace baker replace charlie "
4
3836
by: Cor | last post by:
Hi Newsgroup, I have given an answer in this newsgroup about a "Replace". There came an answer on that I did not understand, so I have done some tests. I got the idea that someone said, that the split method and the regex.replace method was better than the string.replace method and replace function. I did not believe that.
4
2206
by: Roy | last post by:
Hey all, Created an .aspx page using VB as the code behind. Compiler pops up error: "BC30451: Name 'Replace' is not declared." Essentially, it acts as if Replace is a custom function that needs to be declared, not a built in one. What gives? FWIW, the code below occurs within a sub within a class. Thanks for any advice! strSQLQuery =...
3
2472
by: gregpinero | last post by:
Hi guys, What I'm trying to do is find all instances of an acronymn such as IBM on a webpage and replace it with <acronym title="International Business Machines">IBM</acronym>. However in my code below it replace the <, and > with &lt; and &gt;. Thus it replaces IBM with: &lt;acronym title="International Business...
1
2010
by: Random Task | last post by:
Can someone help me by providing an example of how to replace / with \ in a string in xslt2. The characters / and \ seem to cause me grief ... I am trying the below code currently ... Any help is appreciated .. Jim
6
2666
by: DataSmash | last post by:
Hello, I need to search and replace 4 words in a text file. Below is my attempt at it, but this code appends a copy of the text file within itself 4 times. Can someone help me out. Thanks! # Search & Replace file = open("text.txt", "r") text = file.read()
3
3947
by: Hvid Hat | last post by:
Hi I want to highlight (make it bold) a word in some text I'm getting in XML format. My plan was to replace the word with a bold (or span) tag with the word within the tag. I've found the code below and it works fine as long as I'm not adding tags around the to parameter. Can anyone explain to me why it doesn't work with tags? And it needs...
0
7703
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7618
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7926
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7678
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5514
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3656
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3644
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1226
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
944
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.