Posted By

adrianparr on 10/12/10


Tagged

remove numeric str chars characters as3 non-numeric charcodeat charat


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

bigfish
sexyflash
tspitzr


AS3 Remove Non-Numeric Characters from a String


 / Published in: ActionScript 3
 

  1. function removeNonNumericChars($str:String):String {
  2. var newStr:String = "";
  3. for (var i:int = 0; i<$str.length; i++) {
  4. var currentCharCode:Number = $str.charCodeAt(i);
  5. if ((currentCharCode >= 48) && (currentCharCode <= 57)) {
  6. newStr += $str.charAt(i);
  7. }
  8. }
  9. return newStr;
  10. }
  11.  
  12. var myString:String = "#12abc345^67%89)(-@!foo";
  13. trace("myString: "+myString);
  14. myString = removeNonNumericChars(myString);
  15. trace("myString: "+myString);
  16.  
  17. // OUTPUT
  18. // myString: #12abc345^67%89)(-@!foo
  19. // myString: 123456789

Report this snippet  

You need to login to post a comment.