Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Replace Function

Status
Not open for further replies.

arpan

Programmer
Oct 16, 2002
336
IN
Suppose I have the following string in ASP:

<%
Dim strText
strText=&quot;Today is Friday and tomorrow is Friday and tomorrow is a holiday.&quot;
%>

I want replace the 'second' Friday in the above string with Saturday. If I use the Replace function like this:

<%
strText=Replace(strText,&quot;Friday&quot;,&quot;Saturday&quot;)
%>

both the Friday(s) in the above string will be replaced by Saturday. How do I ensure that only the 'second' Friday gets replaced with Saturday so that the output will be &quot;Today is Friday and tomorrow is Saturday and tomorrow is a holiday&quot;? Please note that, in reality, the string is generated dynamically & is not a static one as I have shown above.

Thanks,

Arpan
 
Hi ...
as you know, the Replace function is like this:

Replace(expression, find, replacewith[, start[, count[, compare]]])

you have a Start that if you omit it, Default (1) will be used.
so the only thing you have to do is that say start after first appearance of &quot;Friday&quot; like this :
strText = Replace(strText, &quot;Friday&quot;, &quot;Saturday&quot;, InStr(1, strText, &quot;Friday&quot;) + 6, -1, 1)
n.b. the &quot;6&quot; is the length of &quot;Friday&quot;.
----
TNX.
E.T.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top