Solved

Examining a string of characters

Posted on 2011-03-17
6
349 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 15

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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

PROBLEM:  How to open a cfwindow or run a function on double click of a cfgrid row. One of my clients wanted to be able to double click on a row item to get more detailed information about a transaction and to be able to modify the line items i…
Sometimes databases have MILLIONS of records and we need a way to quickly query that table to return the results me need. Sure you could use CFQUERY but it takes too long when there are millions of records. That is why SOLR was invented. Please …
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

863 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now