Here is my program:
<cfset test = 'a~b~~c~d~~~e'>
<cfset test2 = Replace(test, '~~','~X~','all')>
<cfoutput>
test #test#
<br> test2 #test2#
<br>wanted: a~b~X~c~d~X~X~e
</cfoutput>
The output I got:
test a~b~~c~d~~~e
test2 a~b~X~c~d~X~~e
wanted: a~b~X~c~d~X~X~e
So the output of test2 is wrong This no doubt has to do with the inner workings of the Replace function, but I need it to work correctly.
Does anyone know of a workaround for this problem?
#Replace(ArrayToList(ListToArray(test, '~~', true, true), '~X~'), '~~','~X~','all')#
work for all your use cases? ExampleReplace(test2, '~~','~X~','all')
again ontest2
. Once~~
is replaced with~X~
twice, all the~~
will be removed from the string.<cfset test = 'a~b~~c~d~~~~e'>
. The result was,dynamic wanted: a~b~X~c~d~X~X~X~e
. @BettyMock will have to verify it, but I think you nailed it.