?
Solved

Splitting a String

Posted on 2004-08-03
7
Medium Priority
?
1,367 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
The Ideal Solution for Multi-Display Applications

Check out ATEN’s VS1912 12-Port DP Video Wall Media Player at InfoComm 2017. Kerri describes how easy it is to design creative video walls in asymmetric layouts and schedule detailed playlists ahead of time with its advanced scheduling feature.

 
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 200 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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…
Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
The purpose of this video is to demonstrate how to automatically show related posts at the bottom of a blog post in WordPress. This will be demonstrated using a Windows 8 PC. Plugin “Yet Another Related Posts Plugin” will be used. Go to your…
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…
Suggested Courses

764 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