www.webdeveloper.com
Results 1 to 6 of 6

Thread: Explode, Split

Hybrid View

  1. #1
    Join Date
    Feb 2006
    Location
    Ft Lauderdale
    Posts
    299

    Explode, Split

    I have a date 08-22-1983 and i need to spit it into 3 part
    08
    22
    1983

    Any ides how do do this?
    Thanks

  2. #2
    Join Date
    Dec 2002
    Location
    St. Louis, MO, USA
    Posts
    1,582
    You can use either getToken() or ListGetAt().

    Say your date is a variable. Then set the date format how you want it.
    Code:
    <cfset thisDate = DateFormat(now(),'mm-dd-yyyy')>
    This will display as "07-02-2009". Use the "-" as a delimiter.
    Code:
    <cfset thisMonth = getToken(thisDate,1,"-")>
    <cfset thisMonth = ListGetAt(thisDate,1,"-")>
    Both examples pretty much do the same thing. Get value in first position of a list that is delimited by a hyphen. Then do the same for day and year:
    Code:
    <cfset thisMonth = getToken(thisDate,1,"-")>
    <cfset thisMonth = ListGetAt(thisDate,1,"-")>
    <cfset thisDay = getToken(thisDate,2,"-")>
    <cfset thisDay = ListGetAt(thisDate,2,"-")>
    <cfset thisYear = getToken(thisDate,3,"-")>
    <cfset thisYear = ListGetAt(thisDate,3,"-")>
    ^_^

  3. #3
    Join Date
    Feb 2006
    Location
    Ft Lauderdale
    Posts
    299
    Thanks alot for all your help,
    you would not know how many (-) are in the string?

    incase i would not have a fix number or spacers?

  4. #4
    Join Date
    Feb 2006
    Location
    Ft Lauderdale
    Posts
    299
    PHP Code:
             <cfset SplitVar #URL.modelID# />
            
    <cfquery datasource="XXXXXXX" dbname="XXXXXX"  name="get_memb">
        
            
    SET QUOTED_IDENTIFIER OFF
            INSERT INTO ModelToPart
            
    (modelID,ModelPartID)
            
    VALUES
            
            
    <cfloop index="intI" from="1" to="#(ListLen( SplitVar, ',' )-1)#" step="1">
                <
    cftry>
                    
                   
                    (
    '#URL.modelID#',' #ListGetAt( SplitVar, intI+1, "," )#')
                    , 
                    <
    cfcatch>
                        
    ERROR#CFCATCH.Message#
                    
    </cfcatch>
                </
    cftry>
            </
    cfloop>
            
          
        </
    cfquery>
    <
    cflocation url="http://www.modelproductions.com/book_NweProjct_viewPart.cfm?modelProjectID=#URL.modelProjectID#"
    I am using the code above to create a Query that inserts multiple records.

    Buy I have a extra coma at the end.

    how can i have it that the last coma does not sohw

    Thanks

  5. #5
    Join Date
    Dec 2002
    Location
    St. Louis, MO, USA
    Posts
    1,582
    Are you using a loop to create the list with var = var & "data," (thereby putting a comma at the end of the value with each iteration)? Or are you using ListAppend()?

    ListAppend() will not put the last comma in there. A loop will, unless you know how many iterations there are, in which case you can set a conditional to NOT put the comma in there on the last iteration.

    ListAppend() is the best option, though.

    ^_^

  6. #6
    Join Date
    Feb 2006
    Location
    Ft Lauderdale
    Posts
    299
    Thanks 1000
    you dont know how much you help me

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles