Solved

Splitting a String

Posted on 2004-08-03
7
1,355 Views
Last Modified: 2013-12-20
I am trying to find a function in Coldfusion that is equivalent to the PHP explode function.

I have a string theDate = "7/3/04" and I want to seperate it by "/" into an array so that the first position in the array will be "7" then second will be "3" and the third will be "04". Can anyone give me a code example of how I can do this?
0
Comment
Question by:thecode101
  • 3
  • 3
7 Comments
 
LVL 4

Expert Comment

by:eclipse2k
ID: 11705285
You can handle it like it would be a list, but not delimited with , but with /, for example:

<cfset result = ListToArray(theDate, "/")>

You can also use

<cfset secondValue = ListGetAt(theDate, 2, "/")>


eclipse2k
0
 
LVL 3

Author Comment

by:thecode101
ID: 11705418
I tried this but it is not working.

<cfset result= ListToArray(#theDate#, "/")>
<cfset Month1 = result[0]>
#Month1#

returns the error:
The element at position 1 of dimension 1, of array variable &quot;RESULT,&quot; cannot be found.
0
 
LVL 17

Expert Comment

by:anandkp
ID: 11705527
<cfset result= ListToArray(theDate, "/")>
0
Save on storage to protect fatherhood memories

You're the dad who has everything. This Father's Day, make sure your family memories are protected. My Passport Ultra has automatic backup and password protection to keep your cherished photos and videos safe. With up to 3TB, you have plenty of room to hold the adventures ahead.

 
LVL 4

Expert Comment

by:eclipse2k
ID: 11705576
In Coldfusion, Arrays start at Position 1, not 0!
0
 
LVL 4

Accepted Solution

by:
eclipse2k earned 50 total points
ID: 11705587
Proper solution:

<cfset result= ListToArray(theDate, "/")>
<cfset Month1 = result[1]>
#Month1#
0
 
LVL 17

Expert Comment

by:anandkp
ID: 11705611
oops sorry - i didnt see that carefully ...

<cfset result=ArrayNew()>
<cfset result= ListToArray(theDate, "/")>

#result[0]#
0
 
LVL 17

Expert Comment

by:anandkp
ID: 11705635
yeah eclipse is correct - [0] wont work with CF it starts from [1] ... gosh its time for me to go home ... :)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

One of the typical problems I have experienced is when you have to move a web server from one hosting site to another. You normally prepare all on the new host, transfer the site, change DNS and cross your fingers hoping all will be ok on new server…
When setting up new project requests for our site, one of the most powerful tools our team has available to use is Axure (http://www.axure.com/). It’s a tool for creating software and web prototypes that can function and interact as if it were the a…
The purpose of this video is to demonstrate how to connect a WordPress website to Google Analytics. This will be demonstrated using a Windows 8 PC Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php :…
The purpose of this video is to demonstrate how to integrate Mailchimp with WordPress, by placing a Mailchimp signup form on a WordPress Page or Post. This will be demonstrated using a Windows 8 PC. Mailchimp will be used. Log into your Mailchi…

929 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now