I'm also noticing that in `replaceNoCase` function...
# adobe
r
I'm also noticing that in
replaceNoCase
function, it does not keep the expected case of the search string after replacement. The issue is that I want to replace 'app' with 'aPp'. Instead, it replaces 'app' with 'APP'. Here is an example: https://cffiddle.org/app/file?filepath=7a89e97a-846e-4c37-b96c-2ae8aaf9dbab/97001d3[…]266-9190-00db99167135/3989fe4a-fe71-43c0-a59d-4303754b8f59.cfm Is there a way to manipulate strings with the exact casing in any way?
I think I figured out how to do this. The callback parameter is new to me and replaced "transform" in the return of the callback function with the string I wanted to have replaced and then it works. Here is the working fiddle examaple: https://cffiddle.org/app/file?filepath=01debd50-f0df-478e-af11-bda5b51a5e6a/b7067e0[…]69d-9aa0-3ae0aabe203f/7b9a317a-ab3c-4f5b-bd57-e32388432014.cfm
s
is your example a real case or just a test case. If it is a real case you can skip the callback and just do
Copy code
outStr = replacenocase( myStr, "app", "aPp", "all");
also for the record, the first example you sent is working as expected. it matched the whole
app
so the
UCase(transform)
would uppercase all of it. if you wanted to isolate the second character to uppercase it, it is possible to do so, but you may have to split the string into an array, or use regex with capture groups
r
@Scott Steinbeck Thanks for noticing. The
ucase()
function was not meant to be in there. When the
ucase()
is taken out, the same result happens where the replacement 'app' is all in upper case as 'APP'. I figured out how to resolve the issue and thank you for the suggestion to replace the inline function with the replacement string. I haven't tried that, yet, but I would prefer to do that instead of having the inline function in this case. Thanks for your feedback! Here is the corrected link. https://cffiddle.org/app/file?filepath=a59ae404-6540-4898-be9d-5e9fdee2979f/83d5e1c[…]aa6-9d1c-41414dad3c59/d022884b-887c-4a4f-a6e5-824c05467982.cfm
g
I've been substituting replacenocase with replaceAll(). I reported an ACF bug years ago that's probably gone u fixed that would intermittently throw an error when the "string" value was large. To use nocase with replaceAll(), pass the "(?i)" flag.
r
@gamesover I appreciate your feedback. Do you know roughly how long the text length is when
replacenocase
begins to error?
g
It varies depending on version of CF, JVM and the regex you are using. ACF throws an internal, uncatchable CF error, but Lucee errors can be caught. (But I can't test on TryCF because the Lucee engine is down again.) Here's a gist w/links to my blog & reported ACF bugs. https://gist.github.com/JamoCA/8ccc609618d575d4c87986681d789d13