Revision: 20879
Updated Code
at November 29, 2009 10:33 by mikehins
Updated Code
public static function striplast(string:String, delimiter:*):String { var pattern:RegExp = new RegExp("\\" + delimiter , "i"); var a:Array = string.split(pattern); delete a[a.length-1]; return a.join(delimiter); // turn -> path/to/folder/ into -> /path/to/ } public static function stripfirst(string:String, delimiter:*):String { var pattern:RegExp = new RegExp("\\" + delimiter , "i"); var a:Array = string.split(pattern); delete a[0]; return a.join(delimiter); // turn -> path/to/folder/ into -> /to/folder } public static function listlast(string:String, delimiter:*):String { var pattern:RegExp = new RegExp("\\" + delimiter , "i"); var a:Array = string.split(pattern); return a[a.length-1]; // turn -> path/to/folder/ into -> folder } public static function listfirst(string:String, delimiter:*):String { var pattern:RegExp = new RegExp("\\" + delimiter , "i"); var a:Array = string.split(pattern); return a[0]; // turn -> path/to/folder/ into -> path } public static function listGetAt(string:String, delimiter:*,index:int = 0):String { var pattern:RegExp = new RegExp("\\" + delimiter , "i"); var a:Array = string.split(pattern); if (index > a.length) index = a.length - 1; return a[index] + delimiter // index = 1 turn -> path/to/folder/ into -> to } // var fileExtension:String = StringUtils.listlast("mysoundfile.flac","."); // output -> flac
Revision: 20878
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at November 29, 2009 10:27 by mikehins
Initial Code
public static function striplast(string:String, delimiter:*):String { var pattern:RegExp = new RegExp("\\" + delimiter , "i"); var a:Array = string.split(pattern); delete a[a.length-1]; return a.join(delimiter); } public static function stripfirst(string:String, delimiter:*):String { var pattern:RegExp = new RegExp("\\" + delimiter , "i"); var a:Array = string.split(pattern); delete a[0]; return a.join(delimiter); } public static function listlast(string:String, delimiter:*):String { var pattern:RegExp = new RegExp("\\" + delimiter , "i"); var a:Array = string.split(pattern); return a[a.length-1]; } public static function listfirst(string:String, delimiter:*):String { var pattern:RegExp = new RegExp("\\" + delimiter , "i"); var a:Array = string.split(pattern); return a[0]; } public static function listGetAt(string:String, delimiter:*,index:int = 0):String { var pattern:RegExp = new RegExp("\\" + delimiter , "i"); var a:Array = string.split(pattern); if (index > a.length) index = a.length - 1; return a[index] + delimiter } // var fileExtension:String = MyClass.listlast("mysoundfile.flac","."); // output -> flac
Initial URL
Initial Description
Kinda Coldfusion string functions
Initial Title
String functions
Initial Tags
Initial Language
ActionScript 3