Solved

Splitting a String

Posted on 2004-08-03
7
1,354 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Join & Write a Comment

This is a guide to setting up a new WHM/cPanel Server to be used for web hosting accounts. It is intended for web hosting company administrators and dedicated server owners. For under $99 per month (considering normal rate of Big Data Cetnters like …
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…
The purpose of this video is to demonstrate how to reset a WordPress password if you are locked out and cannot reset the password. A typical use would be if you cannot access the email to which WordPress would send the password recovery email to…
The purpose of this video is to demonstrate how to integrate Mailchimp with Facebook. This will be demonstrated using a Windows 8 PC. Mailchimp and Facebook will be used. Log into your Mailchimp account. : Click on your name. Go to Account Setti…

707 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

14 Experts available now in Live!

Get 1:1 Help Now