Link to home
Start Free TrialLog in
Avatar of Blair Benjamin
Blair BenjaminFlag for United States of America

asked on

Examining a string of characters

This should be a pretty easy one for a ColdFusion guru...

I'm trying to examine a string of characters (a file name) to determine the file type.  However, I need it to search for the first three characters after the first "." in the string, not necessarily the last three characters overall.  This is because of a secondary process that thinks that any characters after the period constitute the extension.   For example, if I have a file called  "movement_I.prelude.mp3" I need to ultimately add logic that does NOT treat this as a .mp3 file.   So what would be the coldfusion command to examine this string to look for the first three characters after the first "." (to see if they EQ "mp3")?

Avatar of Brijesh Chauhan
Brijesh Chauhan
Flag of India image

Consider it as a LIST with Separator as "." and get the last element, using LISTLAST ...
<cfset testStr = 'movement_I.prelude.mp3' />

<cfset lastElement = listlast(testStr,'.') />

<cfoutput> #lastElement# </cfoutput>

Open in new window

Avatar of Coast Line
You can also use the right function if you want to extract the extension like

<cfset testStr = 'movement_I.prelude.mp3' />

<cfset ext = right(testStr,'3')>

otherwise you can use listlast, listfind etc to do that

Cheers
ASKER CERTIFIED SOLUTION
Avatar of rucky544
rucky544
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You can loop through the list to get elements at whatever place you like

<cfloop list="#testStr#" index="i" delimiters=".">
	<cfoutput> #i# <br/></cfoutput>
</cfloop>

Open in new window

Avatar of Blair Benjamin

ASKER

Thanks.  Some of the other suggestions may have worked, but this is the one that most closely matched what I was trying to accomplish and it works great.  Much appreciated.