Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make multi character delimiter in Coldfusion for cfloop?

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

like image 898
CFUser Avatar asked Jan 27 '10 15:01

CFUser


2 Answers

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.

like image 113
Ben Doom Avatar answered Dec 07 '22 14:12

Ben Doom


Use .split() function instead.

For example, you can split a string by a string delimiter like this:

 "string&^&string&^&string".split("&^&")
like image 23
David Liu Avatar answered Dec 07 '22 12:12

David Liu