This content has been marked as final. Show 5 replies
Where are the lists coming from?
IIRC, at least one of the CF8 list functions has a new attribute that can force CF to recognize empty elements.
If MX7 or prior, one option is replace the blanks with a space character or some series of character(s) representing a blank. That will force CF to recognize them as list elements. Just remember to check the first and last list elements too.
Once you have a valid list or array, you can use a loop to construct your new string using listAppend(finalList, ...., "&")
> Now I'm thinking I need to solve this with an array but I have spent hours
> trying to figure it out with no luck.
What have you tried and why doesn't it work?
Okay, I figured it out on my own finally. I stumbled upon the ListToArray function, and did this:
<cfset myNameArray = ListToArray(attributeNameList, ",", "true")>
<cfset myValueArray = ListToArray(attributeValueList, ",", "true")>
This function allows you to count the blank spaces as array members, which is exactly what I needed.
Then it was just a matter of looping over both arrays and putting the values where I needed them, like this:
<cfloop from="1" to="#ArrayLen(myNameArray)#" index="j">
<cfif #myValueArray[j]# eq ""><cfelse>
<cfset attributeNameValuePairs = ListAppend(attributeNameValuePairs, "Attribute.#index#.Name=#myNameArray[j]#Attribute.#index#.Value=#myValueArray[j]#")/>
<cfset index = index + 1/>
This loop says that if the value array is blank, skip it, otherwise match up the name/value pairs. When I output attributeNameValuePairs I get the concatenated string exactly the way I wanted. I love ColdFusion.
See what happens when you read the documentation ;-)