Solved

Examining a string of characters

Posted on 2011-03-17
6
350 Views
Last Modified: 2012-08-13
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")?

0
Comment
Question by:benjaminfam
6 Comments
 
LVL 11

Expert Comment

by:Brijesh Chauhan
ID: 35157098
Consider it as a LIST with Separator as "." and get the last element, using LISTLAST ...
0
 
LVL 11

Expert Comment

by:Brijesh Chauhan
ID: 35157122
<cfset testStr = 'movement_I.prelude.mp3' />

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

<cfoutput> #lastElement# </cfoutput>

Open in new window

0
 
LVL 16

Expert Comment

by:Gurpreet Singh Randhawa
ID: 35157618
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
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 5

Accepted Solution

by:
rucky544 earned 500 total points
ID: 35157706
This RegEx should pick it up, since you don't want the last 3, but the 3 digits after the first .

<cfset filename = "movement_I.prelude.mp3">
<cfset filetype = refindnocase("\.[A-Za-z0-9_]{3}", filename, 1, true) />
<cfset output = mid(filename, filetype.pos[1]+1, filetype.len[1]-1) />

Open in new window

0
 
LVL 11

Expert Comment

by:Brijesh Chauhan
ID: 35157903
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

0
 

Author Closing Comment

by:benjaminfam
ID: 35158444
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.
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Coldfusion redirect to new URL when timeout 4 73
PowerPoint Presentation .PPTX on Coldfusion 10 webpage 5 144
Having an issue with NumberFormat 7 61
expandPath erroring 15 63
Hi, Even though I have created this Tutorial on My personal Blog, Some people might not able to find my website, So here i am posting it again Today, from the topic it is very clear that i will be showing you here the very basic usage of how we …
Recently while working on a project I got a very annoying cfdocument has no body error message. I had never seen this error before. So I checked the code. The code was pretty simple; it was Just showing me the cfdocumnt tag and inside that tag a …
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question