Remove whitespace in as3

后端 未结 4 1816
清歌不尽
清歌不尽 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:41

    You can use RegExp.

    var rex:RegExp = /[\s\r\n]+/gim;
    var str:String = "This is            a string.";
    
    str = str.replace(rex,'');
    // str is now "Thisisastring."
    

    For trimming front and back of strings, use

    var rex:RegExp /^\s*|\s*$/gim;
    

提交回复
热议问题