Skip to main content
AlexCraig
Inspiring
Feb 13, 2024 3:36 PM UTC
Answered

Need Help with Replace Boolean Syntax

OK.  One last item to cure with respect to applicant searches.

In CF 4.51 the collection for applicants was based on a huge folder containing .txt files.

In CF 2023 the colleciton is based on a huge folder containg: .doc, .docx, .pdf & .txt files.

 

The code that worked against the .txt file collection was.

****************************

values (#getCurrentSearchID.theSearchID#, #Replace( replace( URL, "/", "" ), ".txt", "" )#)

****************************

Basically, it stripped off the .txt part of the file name & the "/" that solr inserts into the value of URL> so that we are left with the file # to use in further processing.

I have tried the following against the folder with the 4 extensions mentioned above.

***************************

values (#getCurrentSearchID.theSearchID#, #Replace( replace( URL, "/", "" ), (".doc" or ".docx" or ".txt") ", "" )#)

***************************

CF is not happy with my (".doc" or ".docx" or ".txt") construct.  Would very much appreciate any suggestions.   Would like to avoid CFIF/CFELSE searching each URL returned to see which extension is involved before continuing to process the data, if that is even possible.

 

This topic is closed to new replies. Start a new post to keep the conversation going.
sdsinc_pmascariCorrect answer
Legend
Feb 13, 2024 5:06 PM UTC

Simple as pie:

ReplaceNoCase(ReplaceNoCase(ReplaceNoCase(ReplaceNoCase( replace( URL, "/", "" ), ".doc", "" ), ".docx", "" ), ".txt", "" ), ".pdf", "" )

7 replies

BKBK
Community Expert
Community Expert
Apr 3, 2024 9:17 AM UTC

A suggestion:

<!--- Use \ to escape ".". The regular-expression match is from left to right, so place docx before doc --->
<cfset resultingString = REReplaceNoCase(theURL, "/|\.docx|\.doc|\.txt|\.pdf", "","all")>
Translate
Legend
Feb 13, 2024 3:40 PM UTC

Is this what you're looking for?  Replacing all those extensions in one line?

Replace(Replace(Replace( replace( URL, "/", "" ), ".doc", "" ), ".docx", "" ), ".txt", "" )
Translate
AlexCraig
AlexCraigAuthor
Inspiring
Feb 13, 2024 4:00 PM UTC

Hmm ...

So what this will do is search for all of them and only delete the one that actually exists AND NOT produce an error for those extensions that are not in the URL.  I"ll need to add one more for the .pdf files as well.  Does this look right to you?

Replace(Replace(Replace(Replace( replace( URL, "/", "" ), ".doc", "" ), ".docx", "" ), ".txt", "" ), ".pdf", "" )

Translate
Alex Craig, General Manager&quot;Avid Saltwater Fly Fisherman&quot;
Legend
Feb 13, 2024 4:08 PM UTC

That's correct.  If there is no 'docx' to replace, it just moves on to .txt, then .pdf.  No errors.

 

Might not be the most elegant line of code ever, but gets the job done.

 

Alternatively, I guess you could use listEach():

<cfset theString = replace( URL, "/", "" )>

<cfset alist = ".doc,.docx,.txt,.pdf">

<cfset listEach(alist,function(idx){
    theString = replace(theString,idx,'');
})>
Translate