【发布时间】:2021-08-09 08:58:36
【问题描述】:
谁能解释一下如何检查空白。
extension StringExtensions on String {
bool isNullOrEmpty() => this == null || isEmpty;
// check empty of white spaces
}
谢谢
【问题讨论】:
标签: flutter dart extension-methods
谁能解释一下如何检查空白。
extension StringExtensions on String {
bool isNullOrEmpty() => this == null || isEmpty;
// check empty of white spaces
}
谢谢
【问题讨论】:
标签: flutter dart extension-methods
使用contains方法或者你可以用正则表达式检查,这里是一个例子
extension StringExtensions on String {
bool get isNullOrEmpty {
bool _hasSpace = RegExp(r'\s').hasMatch(this);
// bool _hasSpace = this.contains(' ');
return this == null || isEmpty || _hasSpace;
}
}
【讨论】: