Posted By

merrittwjm on 04/17/14


Tagged

regex as3 spaces


Versions (?)

AS3 RegEx - Remove Spaces


 / Published in: ActionScript 3
 

Remove spaces from a string

  1. //remove all spaces
  2. var myString:String = " this is a test string ";
  3. var space:RegExp = /\s/g;
  4. myString = myString.replace(space, "");
  5.  
  6. // output = thisisateststring
  7.  
  8. //remove spaces on both ends
  9. var myString:String = " this is a test string ";
  10. var pattern:RegExp = /^\s+|\s+$/g;
  11. myString = myString.replace(pattern, "");
  12.  
  13. // output = "this is a test string"
  14.  
  15. var myString:String = "this is a strange string";
  16. var singleSpace:RegExp = /\s{2,}/g;
  17. myString = myString.replace(singleSpace, " ");

Report this snippet  

You need to login to post a comment.