AS3 Trim Whitespace From the Beginning and End of a String


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



Copy this code and paste it in your HTML
  1. function trimWhitespace($string:String):String {
  2. if ($string == null) {
  3. return "";
  4. }
  5. return $string.replace(/^\s+|\s+$/g, "");
  6. }
  7.  
  8. var myString:String = " Hello World ";
  9. trace(trimWhitespace(myString));
  10. // OUTPUT
  11. // Hello World

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.