How to remove all whitespace of a string in Dart?

后端 未结 7 1946
半阙折子戏
半阙折子戏 2021-02-07 10:31

Using trim() to eliminate white space in Dart and it doesn\'t work. What am I doing wrong or is there an alternative?

       String product = \"COC         


        
7条回答
  •  闹比i
    闹比i (楼主)
    2021-02-07 11:22

    Try this

    String product = "COCA COLA";
    print('Product id is: ${product.replaceAll(new RegExp(r"\s+\b|\b\s"), "")}');
    

    Update:

    String name = '4 ever 1 k g @@ @';
    print(name.replaceAll(new RegExp(r"\s+"), ""));
    

提交回复
热议问题