StructToList( objData, strDelimiter1, strDelimiter2, blnUrlEncoded )
Downloadable Files
structtolist_function.cfm.txt ( 4,178 Bytes )
This takes a structure and converts it to a dual-delimited list using the key-value pairs. Currently it only takes the simple values into account and ignores both the key and value of a pair having a non-simple value. There is an option to encode the struct values for passing in the Url.
- <cffunction name="StructToList" access="public" returntype="string" output="no"
- hint="This takes a struct and reutns a string based on two given delimiters. This only uses simple values.">
-
- <!--- Define arguments. --->
- <cfargument name="Data" type="struct" required="yes" />
- <cfargument name="Delimiter1" type="string" required="no" default="&" />
- <cfargument name="Delimiter2" type="string" required="no" default="=" />
- <cfargument name="EncodeUrl" type="boolean" required="no" default="false" />
-
- <cfscript>
-
- // Define the local scope.
- var LOCAL = StructNew();
-
- // Set the default return string.
- LOCAL.Results = "";
-
- // Now, loop over the keys in the struct.
- for (LOCAL.Key in ARGUMENTS.Data){
-
- // Check to see if we have a simple value.
- if (IsSimpleValue( ARGUMENTS.Data[ LOCAL.Key ] )){
-
- // We have a simple value so, add it to the results.
- if (Len(LOCAL.Results)){
- LOCAL.Results = (LOCAL.Results & ARGUMENTS.Delimiter1);
- }
-
- // Add the pair, but check to see if we are supposed to Url Encode the value.
- if ( ARGUMENTS.EncodeUrl ){
-
- // Use Url encoding.
- LOCAL.Results = (
- LOCAL.Results &
- LCase(LOCAL.Key) &
- ARGUMENTS.Delimiter2 &
- UrlEncodedFormat( ARGUMENTS.Data[ LOCAL.Key ] )
- );
-
- } else {
-
- // No Url encoding.
- LOCAL.Results = (
- LOCAL.Results &
- LCase(LOCAL.Key) &
- ARGUMENTS.Delimiter2 &
- ARGUMENTS.Data[ LOCAL.Key ]
- );
-
- }
- }
- }
-
- // Return the results.
- return( LOCAL.Results );
-
- </cfscript>
- </cffunction>
Added May 1, 2006 / Updated May 1, 2006



