I'm trying to clean up submitted file names.
I'm using replacelist(filename,"',##,&, ",",,and,-")
which should
'
and #
&
with and
-
.When given "apost's & pound#.JPG"
, instead of returning:
"aposts-and-pound.jpg"
replaceList returns:
"apostandspound-.JPG"
I'm using ColdFusion 10.
This is not reordering - it is due to how the CF list processing works - empty elements are ignored/removed.
Some of the List~ string processing functions have an additional argument to change this behaviour (i.e. treat empty elements as an empty string), but ReplaceList doesn't appear to.
You can solve this by doing the removals in a separate step to the replacements:
<cfset NewFilename = rereplace(Filename,"['##]","","all") />
<cfset NewFilename = replacelist(NewFilename,"&, ","and,-") />
or
replacelist( rereplace(filename,"['##]","","all") , "&, " , "and,-" )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With