Solved

Examining a string of characters

Posted on 2011-03-17
6
354 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Containers & Docker to Create a Powerful Team

Containers are an incredibly powerful technology that can provide you and/or your engineering team with huge productivity gains. Using containers, you can deploy, back up, replicate, and move apps and their dependencies quickly and easily.

 
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 Team Achieving Their Full Potential?

74% of employees feel they are not achieving their full potential. With Linux Academy, not only will you strengthen your team's core competencies but also their knowledge of of the newest IT topics.

With new material every week, we'll make sure that you stay ahead of the game.

Question has a verified solution.

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

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 …
I spent nearly three days trying to figure out how incorporate OAuth in Coldfusion for the Eventful API. Hopefully, this article will allow Coldfusion Programmers to buzz through the API when they need to. Basically, what this script does is authori…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

695 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