arrays - Coldfusion 将一个阵列一分为二

标签 arrays coldfusion cfquery

我可以将一个数组分成两个单独的数组,原始数组中的每个元素都用“:”分隔吗? “:”之前的文本进入array1,“:”之后的文本进入array2

<cfset tempArr = DeserializeJSON(URL.data) />
<cfset selectList = "" />
    <cfloop array=#tempArr# index="i">
<cfset selectList = listappend(selectList,i) />
</cfloop>

现在这段代码抓取整个元素而不是单独的。

编辑

示例字符串将是:

名字:鲍勃

first_name 进入 selectList1
Bob 进入 selectList2

宏伟的计划同样会有其他领域:

名字:鲍勃

姓氏:Shmo

年龄:27

等等...

编辑:答案

问题已通过使用代码解决
<!---Variables--->
<cfset temp1 = "" />
<cfset temp2 = "" />
<cfset selectList1 = "" /><!---Holds column names for tables--->
<cfset selectList2 = "" /><!---Holds query parameters for column names. Ie,
                                    values for use in the WHERE clause--->

<cfloop array=#tempArr# index="i"><!---Loop through contents of the array--->
    <cfset temp1 = GetToken(i,1,":")/><!---Store the column name--->
    <cfset temp2 = GetToken(i,2,":")/><!---Query parameter--->

    <cfset selectList1 = listAppend(selectList1, temp1)/><!---Adds to list of column names--->
    <cfset selectList2 = listAppend(selectList2, temp2)/><!---Adds to the list of query parameters--->
</cfloop>

最佳答案

我认为没有看到您的数组示例,您的意思是将数组中的数据拆分为两个列表?

<cfset selectList1 = listAppend(selectList1, listFirst(i,':')) >
<cfset selectList2 = listAppend(selectList2, listLast(i,':')) >

关于arrays - Coldfusion 将一个阵列一分为二,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16948546/

相关文章:

Java 对象数组在初始化期间崩溃

c - C 中的动态内存分配 : Problems in Realloc

c++ - 使用 OpenGL 渲染位数组

ajax - 如何使用 Coldfusion.ajax.submitform 传递未选中的复选框值?

coldfusion - 使用 webhooks 和 Coldfusion 的 Twilio 入站 SMS

hibernate - 将 cfqueryparam 与 ColdFusion HQL 查询一起使用

coldfusion - 从 cfscript 中的 Coldfusion newQuery() 获取结果元数据

arrays - 对具有相同范围的多张工作表进行排序

coldfusion - Coldfusion for 循环中是否可以有两个索引?

coldfusion - 我可以在ColdFusion中按索引获取查询吗?