【问题标题】:How to write a extension method to check empty of white spaces dart如何编写扩展方法来检查空白飞镖
【发布时间】:2021-08-09 08:58:36
【问题描述】:

谁能解释一下如何检查空白。

extension StringExtensions on String {

  bool isNullOrEmpty() => this == null || isEmpty;

 // check empty of white spaces


}

谢谢

【问题讨论】:

    标签: flutter dart extension-methods


    【解决方案1】:

    使用contains方法或者你可以用正则表达式检查,这里是一个例子

    extension StringExtensions on String {
      bool get isNullOrEmpty {
        bool _hasSpace = RegExp(r'\s').hasMatch(this);
        //  bool _hasSpace = this.contains(' ');
    
        return this == null || isEmpty || _hasSpace;
      }
    }
    

    【讨论】:

      猜你喜欢
      • 2019-03-17
      • 2012-03-01
      • 2019-03-11
      • 2018-02-23
      • 2015-09-01
      • 2019-02-12
      • 2017-07-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多