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

Looping through String With Multiple Replace Conditions

New Here ,
Jul 29, 2010 Jul 29, 2010

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

529
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

Contributor , Jul 29, 2010 Jul 29, 2010

Can't you do:

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

?

Translate
Contributor ,
Jul 29, 2010 Jul 29, 2010

Can't you do:

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

?

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
LEGEND ,
Jul 29, 2010 Jul 29, 2010
LATEST

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

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
Enthusiast ,
Jul 29, 2010 Jul 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

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