1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

String function need help!

Discussion in 'Programming' started by senloong, May 22, 2007.

  1. #1
    Dear guys,

    Anyone know how to display the value only after the “-” from “Singapore , Singapore - Bangkok, Thailand” in coldfusion. It means I just need to display “Bangkok, Thailand” instead of whole string. Thanks in advance!
     
    senloong, May 22, 2007 IP
  2. Aztral

    Aztral Well-Known Member

    Messages:
    344
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    125
    #2
    Search on "coldfusion split." cflib.org has a udf for a split function. Then you can split on '-'.

    So something like
    <cfset arrMySplit = Split( InStr, '-')>
    <cfoutput>#arrMySplit [2]#</cfoutput> <!--- CF arrays are 1 based -->
     
    Aztral, May 22, 2007 IP
    WillBMX likes this.
  3. senloong

    senloong Peon

    Messages:
    102
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thank you Aztral! Will try it out!
     
    senloong, May 22, 2007 IP
    WillBMX likes this.
  4. Paul_Hopkinson

    Paul_Hopkinson Peon

    Messages:
    14
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Just do a ListGetAt

    <cfset String ="Singapore , Singapore - Bangkok, Thailand">

    <cfoutput>#ListGetAt(string, 2, '-')#</cfoutput>
     
    Paul_Hopkinson, May 23, 2007 IP
  5. WillBMX

    WillBMX Guest

    Messages:
    22
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Or you could do this:

    <cfset string = "Singapore, Singapore - Bangkok, Thailand" />

    <cfset string = replace(string, #string# , "Bangkok, Thailand", "one")
     
    WillBMX, May 23, 2007 IP
  6. Paul_Hopkinson

    Paul_Hopkinson Peon

    Messages:
    14
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    except that is assuming the string isnt dynamically generated - the list get at works with a dynamic string
     
    Paul_Hopkinson, May 23, 2007 IP
  7. WillBMX

    WillBMX Guest

    Messages:
    22
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Very good point.
     
    WillBMX, May 23, 2007 IP
  8. Paul_Hopkinson

    Paul_Hopkinson Peon

    Messages:
    14
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Thank you :)
     
    Paul_Hopkinson, May 23, 2007 IP
  9. datropics

    datropics Peon

    Messages:
    309
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    0
    #9
    Now this is great - you guys are really showing the true dynamism of ColdFusion!!!!
     
    datropics, May 28, 2007 IP