Wrox Programmer Forums
|
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 9th, 2005, 08:29 AM
Friend of Wrox
 
Join Date: Nov 2005
Posts: 223
Thanks: 0
Thanked 0 Times in 0 Posts
Default retrive file extension

Hi,

Does anyone know how to retrive the last part of a variable
something like


if (fileName==_small.jpg)//get last part of filename
{
 action
}

This is my junk I'm gona eat it
 
Old December 9th, 2005, 10:50 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

You could use the lastIndexOf method:
Code:
function getFileExtension(Path)
{
  if (Path)
  {
    var iPos = Path.lastIndexOf(".");
    if (iPos > -1)
    {
      return Path.substr(iPos + 1);
    }
  }
  return "";
}

var sPath = "myfolder\\myfile.jpg";
alert(getFileExtension(sPath));

--

Joe (Microsoft MVP - XML)
 
Old December 10th, 2005, 01:35 PM
Friend of Wrox
 
Join Date: Nov 2005
Posts: 223
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thnx that just did the trick.

This is my junk I'm gona eat it





Similar Threads
Thread Thread Starter Forum Replies Last Post
File extension detection RichardOrmiston ASP.NET 1.0 and 1.1 Basics 2 November 2nd, 2005 11:46 AM
What file extension should I use? pigtail Javascript 3 April 12th, 2004 02:58 PM
Retrive text from input type field of html file?? bikash Javascript 10 July 30th, 2003 04:50 AM
Retrive full path name from uploaded file itsp PHP How-To 3 June 10th, 2003 07:02 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.