Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

replace only 5 th occurance in the string

Explorer ,
Mar 28, 2008 Mar 28, 2008
Replace & ReplaceAll replaces string with other string but I want to only replace say fifth occurrence of '<a id=Anchor' with '<a style="....."'. First, second & other occurrences of <a should not be replaced. Any suggestions?
thanks
TOPICS
Getting started
297
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Explorer , Mar 28, 2008 Mar 28, 2008
<cftry>
<cfset Highlight_MenuNo = 5>

<cfset MenuHtml = LeftMenuHtml>

<cfset CountVar = 1>
<cfset StartPos = 1>
<cfset Posi = 1>
<cfloop condition="CountVar LESS THAN OR EQUAL TO Highlight_MenuNo">
<cfset CountVar = CountVar + 1>

<cfset Posi = Find('color:HighLightMe;', MenuHtml, StartPos)>
<cfset StartPos = Posi + 18>
</cfloop>
<cfcatch>error in startPos</cfcatch></cftry>


<cfoutput>#Left(LeftMenuHtml,Evaluate('StartPos -19'))#color:##88ab2e;border:0px;#Right(LeftMenuHtml,Evaluat...
Translate
Contributor ,
Mar 28, 2008 Mar 28, 2008
Find the fifth and make a single replace. 🙂
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 28, 2008 Mar 28, 2008
LATEST
<cftry>
<cfset Highlight_MenuNo = 5>

<cfset MenuHtml = LeftMenuHtml>

<cfset CountVar = 1>
<cfset StartPos = 1>
<cfset Posi = 1>
<cfloop condition="CountVar LESS THAN OR EQUAL TO Highlight_MenuNo">
<cfset CountVar = CountVar + 1>

<cfset Posi = Find('color:HighLightMe;', MenuHtml, StartPos)>
<cfset StartPos = Posi + 18>
</cfloop>
<cfcatch>error in startPos</cfcatch></cftry>


<cfoutput>#Left(LeftMenuHtml,Evaluate('StartPos -19'))#color:##88ab2e;border:0px;#Right(LeftMenuHtml,Evaluate('Len(LeftMenuHtml) - StartPos'))#</cfoutput>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources