flutter - 如何编写扩展方法来检查空白飞镖
问题描述
任何人都可以解释一下如何检查空白。
extension StringExtensions on String {
bool isNullOrEmpty() => this == null || isEmpty;
// check empty of white spaces
}
谢谢
解决方案
使用contains
方法,或者你可以用正则表达式检查它,这里是一个例子
extension StringExtensions on String {
bool get isNullOrEmpty {
bool _hasSpace = RegExp(r'\s').hasMatch(this);
// bool _hasSpace = this.contains(' ');
return this == null || isEmpty || _hasSpace;
}
}
推荐阅读
- sql - 如何计算 BigQuery 中每天添加的平均记录数。?
- ssis - SSIS。OLE DB 源代码编辑器 - 表或视图 - 是否锁定它正在读取的表?
- sql - SQL 将行连接到列
- node.js - 如何提取变量的内容并将它们放入常量中?节点.js
- parallel-processing - 如何使用阿姆达尔定律(整体加速与加速)
- google-maps - 如何在 Flutter 中包含本机代码以在 Google 地图上显示 KML 图层?
- mysql - 为什么 RAND 有时会在 MySQL 调用中产生多个结果?
- oauth-2.0 - 具有 oauth2 和客户端凭据授予类型的密钥斗篷,用于向我的公共 API 验证外部客户端(服务/应用程序)
- node.js - 哪个包更适合在真实项目 mongodb 或 mongoose 中使用?
- python - 使用滑动窗口时尝试保存图像时出现问题