Skip to main content

Posts

Showing posts with the label structure

How to update a structure key with a value in ColdFusion

StructUpdate() - update a structure key with a value StructUpdate.cfm <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>StructUpdate function example: how to update a structure key with a value</title> </head> <body> <h2 style="color:HotPink">StructUpdate Function Example</h2> <cfset Color=StructNew()> <cfset Color.ID=1> <cfset Color.Name="LightGray"> <cfset Color.Value="##D3D3D3"> <cfdump var="#Color#" label="Color"> <br /> <cfset Temp=StructUpdate(Color,"Name","LightGreen")> <cfset Temp=StructUpdate(Color,"Value","##90EE90")> <cfdump var="#Color#" label="Color[after update]"> </body> </html> More ColdFusion example...

How to create a structure in ColdFusion

Introduction ColdFusion is a powerful and easy-to-use platform for building dynamic web applications. One of its useful features is the ability to create and manage complex data structures. In this article, we will focus on creating structures (also known as associative arrays or dictionaries in other languages) using ColdFusion's StructNew function. A structure is a collection of key-value pairs, making it an excellent tool for organizing related data, such as information about an employee. This tutorial demonstrates a simple yet effective example of creating a structure to store employee information. We'll break down the components of the code and explain how ColdFusion allows developers to work efficiently with structures. Let’s dive into the example to better understand how the StructNew function works in practice. Creating the Structure with StructNew() In ColdFusion, structures are created using the StructNew() function. This function initializes a new, empty structure...

How to get a list of keys from a structure in ColdFusion

StructKeyList() - get a list of keys from a structure StructKeyList.cfm <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>StructKeyList function example: how to get a list of keys from a structure</title> </head> <body> <h2 style="color:HotPink">StructKeyList Function Example</h2> <cfset Color=StructNew()> <cfset Color.ID=1> <cfset Color.Name="LightGoldenRodYellow"> <cfset Color.Value="##FAFAD2"> <cfdump var="#Color#" label="Color"> <cfset KeyList=StructKeyList(Color,";")> <br /> <cfoutput> <b> Color Structure Key List: #KeyList# </b> </cfoutput> </body> </html> More ColdFusion examples StructClear() - remove all data from a structure StructCount() - co...

How to check whether a specific key is present in a structure in ColdFusion

StructKeyExists() - check whether a specific key is present in a structure StructKeyExists.cfm <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>StructKeyExists function example: how to check whether a specific key is present in a structure</title> </head> <body> <h2 style="color:HotPink">StructKeyExists Function Example</h2> <cfset Color=StructNew()> <cfset Color.ID=1> <cfset Color.Name="LightCyan"> <cfset Color.Value="##E0FFFF"> <cfdump var="#Color#" label="Color"> <br /> <cfoutput> <b> Color Structure Key Exists[Name]?: #StructkeyExists(Color,"Name")# <br /> Color Structure Key Exists[Names]?: #StructkeyExists(Color,"Names")# </b> </cfoutput> </body> ...

How to get an array of keys from a structure in ColdFusion

StructKeyArray() - get an array of keys from a structure StructKeyArray.cfm <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>StructKeyArray function example: how to get an array of keys from a structure</title> </head> <body> <h2 style="color:HotPink">StructKeyArray Function Example</h2> <cfset Color=StructNew()> <cfset Color.ID=1> <cfset Color.Name="LightCoral"> <cfset Color.Value="##F08080"> <cfdump var="#Color#" label="Color"> <br /> <cfset ColorKeyArray=StructKeyArray(Color)> <cfdump var="#ColorKeyArray#" label="Color[Structure Key array]"> </body> </html> More ColdFusion examples StructCount() - count the keys in a structure StructDelete() - remove an el...

ColdFusion - How to determine whether a structure contains data

StructIsEmpty() - determine whether a structure contains data StructIsEmpty.cfm <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>StructIsEmpty function example: how to determine whether a structure contains data</title> </head> <body> <h2 style="color:HotPink">StructIsEmpty Function Example</h2> <cfset Color=StructNew()> <cfset Color.ID=1> <cfset Color.Name="LightBlue"> <cfset Color.Value="##ADD8E6"> <cfoutput> <b> Color Structure Is Empty?: #StructIsEmpty(Color)# </b> </cfoutput> <cfdump var="#Color#" label="Color"> <cfset Temp=StructClear(Color)> <br /> <cfoutput> <b> Color Structure Is Empty[after remove all data]?: #StructIsEmpty(Color)# </b> </cfoutput...

How to insert a key value pair into a structure in ColdFusion

StructInsert() - insert a key value pair into a structure StructInsert.cfm <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>StructInsert function example: how to insert a key value pair into a structure</title> </head> <body> <h2 style="color:HotPink">StructInsert Function Example</h2> <cfset Color=StructNew()> <cfdump var="#Color#" label="Color"> <cfset Temp=StructInsert(Color,"ID",1,"yes")> <cfset Temp=StructInsert(Color,"Name","Green","yes")> <cfset Temp=StructInsert(Color,"Value","##008000","yes")> <br /> <cfdump var="#Color#" label="Color[after insert data]"> </body> </html> More ColdFusion examples Is...

How to get the value associated with a key in a structure in ColdFusion

StructFind() - find the value associated with a key in a structure StructFind.cfm <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>StructFind function example: how to get (find) the value associated with a key in a structure</title> </head> <body> <h2 style="color:HotPink">StructFind Function Example</h2> <cfset Color=StructNew()> <cfset Color.ID=1> <cfset Color.Name="LemonChiffon"> <cfset Color.Value="##FFFACD"> <cfdump var="#Color#" label="Color"> <br /> <cfset NameKey=StructFind(Color,"Name")> <cfoutput> <b> Color Structure Name key: #NameKey# </b> </cfoutput> </body> </html> More ColdFusion examples StructAppend() - append one structure to another ...

How to remove an element from a structure in ColdFusion

Introduction In Adobe ColdFusion, structures are versatile data types that allow you to store and organize key-value pairs efficiently. Managing the contents of a structure often involves adding, modifying, and deleting elements based on various conditions. One of the most common operations when working with structures is deleting specific elements, which can help optimize your code and free up memory. In this tutorial, we will explore how to remove an element from a structure using ColdFusion’s StructDelete() function. In this example, we will walk through a simple ColdFusion page that demonstrates how to create a structure, populate it with data, and then remove an element. This tutorial is ideal for those who want to learn how to manipulate ColdFusion structures efficiently and effectively. Creating a Structure in ColdFusion The first step in this example is creating a structure to hold key-value pairs. ColdFusion provides the StructNew() function, which is used to create an empty...

How to count the keys of a structure in ColdFusion

StructCount() - count the keys in a structure StructCount.cfm <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>StructCount function example: how to count the keys in a structure</title> </head> <body> <h2 style="color:HotPink">StructCount Function Example</h2> <cfset Color=StructNew()> <cfset Color.ID=1> <cfset Color.Name="LavenderBlush"> <cfset Color.Value="##FFF0F5"> <cfdump var="#Color#" label="Color"> <br /> <cfoutput> <b> Color[key count]: #StructCount(Color)# </b> </cfoutput> </body> </html> More ColdFusion examples StructAppend() - append one structure to another StructClear() - remove all data from a structure StructDelete() - remove an element from a structu...

How to remove all data from a structure in ColdFusion

StructClear() - remove all data from a structure StructClear.cfm <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>StructClear function example: how to remove all data from a structure</title> </head> <body> <h2 style="color:HotPink">StructClear Function Example</h2> <cfset Color=StructNew()> <cfset Color.ID=1> <cfset Color.Name="Ivory"> <cfset Color.Value="##FFFFF0"> <cfdump var="#Color#" label="Color"> <cfset Temp=StructClear(Color)> <br /> <cfdump var="#Color#" label="Clear[After clear data]"> </body> </html> More ColdFusion examples IsStruct() - check whether a variable is a structure StructAppend() - append one structure to another StructCount() - cou...

How to append a structure to another in ColdFusion

Introduction In Adobe ColdFusion, working with structures (also known as associative arrays in other languages) is a fundamental concept that enables developers to store and organize data using key-value pairs. One common operation when handling structures is the need to merge or append data from one structure into another. The StructAppend function is specifically designed for this purpose, allowing developers to append all key-value pairs from one structure into another with minimal effort. This tutorial demonstrates how to use the StructAppend function in ColdFusion to append one structure to another, using a simple example that involves two structures representing color information. We will walk through the process step by step to give you a clear understanding of how the function works and how it modifies the target structure. Creating and Defining the First Structure The first step in this example is the creation of a structure named Color . This structure is initialized using ...

How to check whether a variable is a structure in ColdFusion

IsStruct() - check whether a variable is a structure IsStruct.cfm <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>IsStruct function example: how to check whether a variable is a structure</title> </head> <body> <h2 style="color:HotPink">IsStruct Function Example</h2> <cfset Color="Red"> <cfoutput> <b> Color: #Color# <br /> Color is a Structure?: #IsStruct(Color)# <br /><br /> </b> </cfoutput> <cfset Color=StructNew()> <cfset Color.ID=1> <cfset Color.Name="IndianRed"> <cfset Color.Value="##CD5C5C"> <cfdump var="#Color#" label="Color"> <br /> <cfoutput> <b> Now Color is a Structure?: #IsStruct(Color)# </b> </cfoutput> </body...