Remove whitespace in as3

后端 未结 4 1845
清歌不尽
清歌不尽 2021-02-19 05:47

How can one remove whitespace from a string in as3?

I would like to be able to remove all carriage returns, spaces, tabs etc.

4条回答
  •  天涯浪人
    2021-02-19 06:43

    The simplest way of removing not only spaces but any char for that matter, is as follows,

    //Tested on Flash CS5 and AIR 2.0
    
    //Regular expressions
    var spaces:RegExp = / /gi; // match "spaces" in a string
    var dashes:RegExp = /-/gi; // match "dashes" in a string
    
    //Sample string with spaces and dashes
    var str:String = "Bu  s ~ Tim  e - 2-50-00";
    str = str.replace(spaces, ""); // find and replace "spaces"
    str = str.replace(dashes, ":"); // find and replace "dashes"
    
    trace(str); // output: Bus~Time:2:50:00
    

提交回复
热议问题