Home > ASP Development > ASP Replace() for multiple items in one execution

ASP Replace() for multiple items in one execution



I was wondering if anyone knows if there is a way to replace multiple items in ASP in a single execution of the function?



Consider this issue:



mytext = "this is not it"

mytext = Replace(mytext, "s", "<strong>s</strong>)

mytext = Replace(mytext, "n", "<strong>n</strong>)



This would produce:

thi<stro<strong>n<s/trong>g>s</stro<strong>n</strong>g> i<stro<strong>n</strong>g>s</stro<strong>n</strong>g> <strong>n</strong>ot it



While it would ideally produce:

thi<strong>s</strong> i<strong>s</strong> <strong>n</strong>ot it

    
Guest


try like this


Code:



mytext = "this is not it"
mytext = Replace(mytext, "s", "<b>s</b>)
mytext = Replace(mytext, "n", "<b>n</b>)



Was this answer helpful ? Yes No   
Guest


This might also help

http://www.freevbcode.com/ShowCode.Asp?ID=2251

Was this answer helpful ? Yes No   
Guest


Quote:
Originally Posted by Guddu
try like this


Code:



mytext = "this is not it"
mytext = Replace(mytext, "s", "<b>s</b>)
mytext = Replace(mytext, "n", "<b>n</b>)






In additon to <b> being a deprecated tag, this simply duplicates my problem.



mytext = "this is not it"

mytext = Replace(mytext, "s", "<b>s</b>)

mytext = Replace(mytext, "b", "<b>b</b>)



What you wrote would produce:

thi<<b>b</b>>s<<b>b</b>> i<<b>b</b>>s<<b>b</b>> not it

Was this answer helpful ? Yes No   
Guest


Quote:
Originally Posted by nofriends
This might also help

http://www.freevbcode.com/ShowCode.Asp?ID=2251




Seems to be VB rather than VBScript. Produces errors if you put it in an ASP page.



Either way, that code is just a loop that would exactly reproduce my problem.... just automated.

Was this answer helpful ? Yes No   
Guest


I was wondering, cant you do that with RegEx?



I am not to clued up on RegEx, but I am sure you will

be able to do it with that.

Was this answer helpful ? Yes No   
Guest


Quote:
Originally Posted by nofriends
I was wondering, cant you do that with RegEx?



I am not to clued up on RegEx, but I am sure you will

be able to do it with that.




Good chance. I don't know enough about ASP's RegEx either. I could do it in Perl but that's not a possibility here.

Was this answer helpful ? Yes No   
Guest


do like this


Code:



<%
mytext = "this is not it"

Set re = New RegExp
re.Pattern = "([snSN])"
re.Global = True

mytext = re.Replace( mytext, "<strong>$1</strong>" )
%>
Yeah,you simply put any characters you *do* want made strong into the list inside the brackets.



Was this answer helpful ? Yes No   
Guest


hmm.... classic way around the problem:


Code:


mytext = "this is not it"
mytext = Replace(mytext, "s", "<*1>s</*1>")
mytext = Replace(mytext, "n", "<*1>n</*1>")
mytext = Replace(mytext, "*1", "strong")



Was this answer helpful ? Yes No   
Guest


You can't do multiple substitutions with the Replace function, so if regex's won't work you are stuck with multiple calls to replace.



http://msdn.microsoft.com/library/e...1b8ed696d0a.asp

Was this answer helpful ? Yes No   
Guest
 
 
Home - About Infoqu - Contact - Privacy Statement - Link to Infoqu - Bookmark Infoqu

Copyright 2007-2008 by Infoqu. All rights reserved