Skip to main content
Inspiring
May 22, 2009
Answered

Extract text from string

  • May 22, 2009
  • 2 replies
  • 794 views

How would I extract everything before and after the LAST - (dash)?

Example: mt-st-marys-fl............................

Everything before last dash: mt-smarys

Everything after last dash: fl

    This topic has been closed for replies.
    Correct answer mack_

    Mack

    2 replies

    BKBK
    Community Expert
    Community Expert
    May 24, 2009

    I would always try to minimize the number of function calls (ideally one) and the number of arguments. If there is nothing else to consider about the test string, then I would just do something like

    <cfset teststring = "mt-st-marys-fl">

    text before last dash: <cfoutput>#left(teststring,11)#</cfoutput><br>
    text after last dash: <cfoutput>#right(teststring,2)#</cfoutput>

    mack_Correct answer
    Participating Frequently
    May 22, 2009

    Mack