how to arrange given list in a particular order in coldfusion

 Consider we have a list as given below:

<cfset list1= "firstname, lastname, middlename, address ,email" />

and if we need this list to be ordered as <cfset order_list = "2,4,3,1,5" /> where order_list is the order for list1 to be arranged.

Let us try to arrange the List1 in the given order of Order_list.


<cfset list1= "first_name, last_name, middle_name, badge_name,email" />

<cfset order_list = "2,4,3,1,5" />

<cfoutput>

New List Order : #order_list# <br>

</cfoutput>

<!---Arrange the values in list one with the order specified in list 2. --->

<cfset newlist1 = "" />

<cfloop list = "#order_list#" index="i">

<cfset newlist1 = listAppend(newlist1, listGetAt(list1, i, ',')) />

</cfloop>

<br/>

<cfoutput> First order is : #newlist1# <br></cfoutput>


Comments

Popular posts from this blog

how to add new line in google form questions | Fix for next line issue in google form questions

How to add new line in dropdown type question in google forms