/ Published in: ActionScript 3
Kinda Coldfusion string functions
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
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