Skip to main content
Participant
July 29, 2010
Answered

Looping through String With Multiple Replace Conditions

  • July 29, 2010
  • 2 replies
  • 631 views

I'm looking to loop through a url string to grab parse out http://,  www.twitter.com, and twitter.com.

I thought of first using this:

<cfset form.mystring = REPLACENOCASE(form.mystring, "http://", "", "One")

AND  REPLACENOCASE(form.mystring, "www.twitter.com", "", "One")>.

I realized that this won't work of course.

Additionally, using a cfif-cfelseif in this case will remove an one condtion, but not multiple condition.

Need to use a cfloop I think. Any  suggestions on syntax.  Thanks

    This topic has been closed for replies.
    Correct answer BreakawayPaul

    Can't you do:

    replacelist(lcase(form.mystring),"http://,www.twitter.com,twitter.com",",,,")

    ?

    2 replies

    Inspiring
    July 29, 2010

    Have you checked to see what is available on CFLIB.ORG?  I'm pretty sure that there are a number of functions there for disecting URL strings.

    -reed

    BreakawayPaul
    BreakawayPaulCorrect answer
    Inspiring
    July 29, 2010

    Can't you do:

    replacelist(lcase(form.mystring),"http://,www.twitter.com,twitter.com",",,,")

    ?

    Inspiring
    July 29, 2010

    An alternative would be to use a regex (which seems - to me - to be a more natural solution here):

    reReplaceNoCase(form.myString, "^http://(?:www\.)?twitter\.com", "", "ONE")

    --

    Adam