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
Was this answer helpful ?
Yes No
This might also help
http://www.freevbcode.com/ShowCode.Asp?ID=2251
Was this answer helpful ?
Yes No
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
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
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
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
Was this answer helpful ?
Yes No
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
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