Search code examples
coldfusioncoldfusion-9cfml

How to split a String by last delimiter in ColdFusion


In CF9, I have a string like C:\Docs\472837\nyspflsys\Medical Report\XLSX_46.xlsx

I want to split it by last backward slash, so it should look like
array[1] = C:\Docs\472837\nyspflsys\Medical Report and
array[2] = XLSX_46.xlsx

How to do it in ColdFusion 9 ?


Solution

  • <cfset myString = "C:\Docs\472837\nyspflsys\Medical Report\XLSX_46.xlsx" />
    <cfset myArray = ArrayNew(1) /> 
    <cfset myArray[2] = ListLast(myString, "\") />
    <cfset myArray[1] = REReplace(myString, "\\" & myArray[2] & "$", "") />
    
    
    <cfdump var="#myArray#" />