String functions


/ Published in: ActionScript 3
Save to your folder(s)

Kinda Coldfusion string functions


Copy this code and paste it in your HTML
  1. public static function striplast(string:String, delimiter:*):String
  2. {
  3. var pattern:RegExp = new RegExp("\\" + delimiter , "i");
  4. var a:Array = string.split(pattern);
  5. delete a[a.length-1];
  6. return a.join(delimiter);
  7. // turn -> path/to/folder/ into -> /path/to/
  8. }
  9. public static function stripfirst(string:String, delimiter:*):String
  10. {
  11. var pattern:RegExp = new RegExp("\\" + delimiter , "i");
  12. var a:Array = string.split(pattern);
  13. delete a[0];
  14. return a.join(delimiter);
  15. // turn -> path/to/folder/ into -> /to/folder
  16. }
  17. public static function listlast(string:String, delimiter:*):String
  18. {
  19. var pattern:RegExp = new RegExp("\\" + delimiter , "i");
  20. var a:Array = string.split(pattern);
  21. return a[a.length-1];
  22. // turn -> path/to/folder/ into -> folder
  23. }
  24. public static function listfirst(string:String, delimiter:*):String
  25. {
  26. var pattern:RegExp = new RegExp("\\" + delimiter , "i");
  27. var a:Array = string.split(pattern);
  28. return a[0];
  29. // turn -> path/to/folder/ into -> path
  30. }
  31. public static function listGetAt(string:String, delimiter:*,index:int = 0):String
  32. {
  33. var pattern:RegExp = new RegExp("\\" + delimiter , "i");
  34. var a:Array = string.split(pattern);
  35. if (index > a.length) index = a.length - 1;
  36. return a[index] + delimiter
  37. // index = 1 turn -> path/to/folder/ into -> to
  38. }
  39.  
  40. // var fileExtension:String = StringUtils.listlast("mysoundfile.flac",".");
  41. // output -> flac

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.