Removing set number of characters from end of string with ColdFusion

16,594
Left(mystring, len(mystring)-6)
Share:
16,594

Related videos on Youtube

Simon Hume
Author by

Simon Hume

Updated on April 25, 2022

Comments

  • Simon Hume
    Simon Hume about 2 years

    Simple request (hopefully) here.

    I have a string which whilst it varies in length, will always need the last 6 characters removed.

    Using a 3rd party web service, so I'm unable to edit the response in the XML before outputting.

    If anyone can suggest a quick way of trimming them off i'd be really grateful!

    here is the string i'll be using:

    #daysEvent[iItem].XmlChildren[iEvent].XmlChildren[16].XmlText#
    

    Thanks!

  • Simon Hume
    Simon Hume almost 14 years
    Great! I think my brain has melted due to the fact it's hot and it's Friday. Thanks for your help!
  • DaEagle
    DaEagle almost 14 years
    It really is too bad that coldfusion does not support negative numbers in its string functions like many other languages do.
  • Peter Boughton
    Peter Boughton almost 14 years
    If enough people ask for it, it might get added - feature requests can be made here: adobe.com/cfusion/mmform/index.cfm?name=wishform
  • Husnain Iqbal
    Husnain Iqbal over 9 years
    If we have <cfset currentDateTime=Now()> i.e. <cfset currentDateTime= "{ts '2014-08-19 02:33:07'}"> THEN <cfset currentDateTime = Left(currentDateTime, len(currentDateTime)-2)> <cfset currentDateTime = Right(currentDateTime, len(currentDateTime)-5)> WILL RESULT 2014-08-19 02:33:07 :) :)