[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Examining a string of characters

Posted on 2011-03-17
6
Medium Priority
?
358 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 5

Accepted Solution

by:
rucky544 earned 2000 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

This is an updated version of a post made on my blog over 3 years ago. It is unfortunately, still very relevant as we continue to see both SQLi (SQL injection) and XSS (cross site scripting) attacks hitting some of the most recognizable website and …
CFGRID Custom Functionality Series -  Part 1 Hi Guys, I was once asked how it is possible to to add a hyperlink in the cfgrid and open the window to show the data. Now this is quite simple, I have to use the EXT JS library for this and I achiev…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

656 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