I have a String variable which has dynamic user entered text
EX:- <cfset setPars="SPTO_DATE('04/11/2009 11:59:59 PM', 'MM/DD/YYYY HH:MI:SS AM')SP(L','MN)>'
Now If I use SP
as the delimiter
in CFloop as below
<cfloop index="i" from="1" To="#ListLen(setPars,'SP')#">
<br/> #ListGetAT(setPars,i,'SP')#
</cfloop>
I am getting output As
TO_DATE('04/11/2009 11:59:59
M', 'MM/DD/YYYY HH:MI:
But I want as
TO_DATE('04/11/2009 11:59:59 PM', 'MM/DD/YYYY HH:MI:SS AM')
(L','MN)
Is there any way in Coldfusion to do that?
Thanks
There is not a direct way to do this. However, there are a couple of different ways to accomplish it.
What I usually do is replace the multichararacter delimiter with a single character. I usually use the bell (chr(7)) because it's not typable on a standard keyboard.
<cfset list = replace(setPars, 'SP', '#chr(7)#', 'all')>
Then, you can loop over the list:
<cfloop list="#list#" index="i" delimiters="#chr(7)#">
<br />#i#
</cfloop>
Note the simpler loop operator. It will save you some work.
Use .split() function instead.
For example, you can split a string by a string delimiter like this:
"string&^&string&^&string".split("&^&")
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