Use lastIndexOf to get the file name without extension name : substr « String « Flash / Flex / ActionScript






Use lastIndexOf to get the file name without extension name

 

package{
  import flash.display.Sprite;
  
  public class Main extends Sprite{
    public function Main(){

        var filename:String = "document.jpg";
        var extensionIndex:Number = filename.lastIndexOf( '.' );
        
        var extensionless:String = filename.substr( 0, extensionIndex ); 
        trace( "The filename is " + extensionless );


    }
  }
}

        








Related examples in the same category

1.Working with Substring Values: substr
2.Optionally omit the second parameter, substr returns a substring starting at the specified index and going to the end of the original string.
3.Specifying a negative value simply counts backward from the end of the string where -1 is the last character.
4.substring method returns a substring starting with the starting index specified and containing all the characters up to, but not including, the ending index.