SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    Under Construction Poop_Shoot's Avatar
    Join Date
    Jul 2003
    Location
    Sacramento, CA
    Posts
    330
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Spliting by Extestion?

    Hello everyone! I was wondering if I had an array with a list of file paths!
    Code:
    var myFiles=new Array("c:\images\image1.gif","c:\images\image2.jpg","c:\images\image1.gif","c:\images\image1.jpg" )
    
    var myFiles=new Array(".gif",".jpg",".gif",".jpg" )
    I am pretty sure it has to do with the split("." ) method I am just not sure as to the syntax!

    Thanx for your help!
    Jon

  2. #2
    SitePoint Evangelist Mr. Brownstone's Avatar
    Join Date
    May 2002
    Location
    Relative
    Posts
    452
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Poop_Shoot
    I was wondering if I had an array with a list of file paths!
    No, you have two arrays of file-names and extensions respectively!
    Of course, that's just my opinion. I could be wrong.

  3. #3
    "Of" != "Have" bronze trophy Jeff Lange's Avatar
    Join Date
    Jan 2003
    Location
    Calgary, Canada
    Posts
    2,063
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What exactly are you trying to achieve?
    Who walks the stairs without a care
    It shoots so high in the sky.
    Bounce up and down just like a clown.
    Everyone knows its Slinky.

  4. #4
    The doctor is in... silver trophy MarcusJT's Avatar
    Join Date
    Jan 2002
    Location
    London
    Posts
    3,509
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You're defining the same variable twice, and overwriting the first array with the second...

    I'm with Jeff Lange on this one...!
    MarcusJT
    - former ASP web developer / former SPF "ASP Guru"
    - *very* old blog with some useful ASP code

    - Please think, Google, and search these forums before posting!

  5. #5
    Under Construction Poop_Shoot's Avatar
    Join Date
    Jul 2003
    Location
    Sacramento, CA
    Posts
    330
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok let me ask a simpler question! Say I have a var!

    var str="abcdef.ghij"

    this is basically what I would like to achieve!

    var newStr=".ghij"

    How could I return just the characters from the decimal point on?

  6. #6
    "Of" != "Have" bronze trophy Jeff Lange's Avatar
    Join Date
    Jan 2003
    Location
    Calgary, Canada
    Posts
    2,063
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    var newStr = str.replace(/^[^\.]*(\..*)$/, '$1');
    would probably be the easiest, (I can't remember how to do strrchr in Javascript right now, lol)
    Who walks the stairs without a care
    It shoots so high in the sky.
    Bounce up and down just like a clown.
    Everyone knows its Slinky.

  7. #7
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How's this?
    Code:
    Array.prototype.applyMethod = function( method, notMutate )
    {
    	var arr = ( notMutate ) ? new Array() : this;
    	for ( var i = 0; i < this.length; i++ )
    	{
    		if ( typeof this[i][method] != 'undefined' ) arr[i] = this[i][method]();
    	}
    	if ( notMutate ) return arr;
    }
     
    String.prototype.getExtension = function()
    {
    	return this.match( /\.\w+$/ )[0];
    }
     
    var myFiles = new Array( 
    	"c:\images\image1.gif",
    	"c:\images\image2.jpg",
    	"c:\images\image1.gif",
    	"c:\images\image1.jpg"
    	);
    
    alert( myFiles );
    myFiles.applyMethod( 'getExtension' );
    alert( myFiles );
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev





Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •