I've been struggle with splitting an address field in my database into it's separate components.
I am pulling address data from my database that is stored in column #company_address# . The data looks like this when I output it:
Address1 Address2 (Not always present) City, State Zip (Sometimes there is a comma, sometimes there is not)
I would like to break up the string in #company_address# and assign each part of the address to it's own variable: variable1 - address1 variable2 - address2 variable3 - city variable4 - state variable5 - zip
Once I have that data, I will enter it back into the db in its seperated form.
I have tried using the listtoarray function but it assigns the whole string to one array element and seems to skip the address2 line entirely.
Here is the code I am using:
<!--- Select ticket record --->
<cfquery name="get_ticket" datasource="#datasource#">
SELECT *
FROM closed_tickets
where ticket_id = #url.ticket_id#
</cfquery>
<cfoutput>
<cfset list = "#get_ticket.company_address#">
<cfset arr = listToArray (list, 'ch(13)' ,false,true)>
<cfdump var="#arr#">
</cfoutput>
Can anyone help??
The problem is that you are using chr(13)
as a string. Use the following.
<cfset arr = listToArray (list, chr(13) , false, true)>