【问题标题】:Flutter | How to check if String does not contain a substring or a character颤振 |如何检查字符串是否不包含子字符串或字符
【发布时间】:2021-11-10 16:34:30
【问题描述】:

我正在学习 Flutter/Dart,我想执行一项检查 - 验证输入电子邮件的用户是否应在其中包含 @

String myString = 'Dart';

// just like i can do the following check
myString.contains('a') ? print('validate') : print('does not validate')

// I want to do another check here
myString does not contain('@') ? print('does not validate'): print('validate')

有人可以建议是否有任何内置函数可以做这样的事情。

【问题讨论】:

    标签: string flutter dart contains


    【解决方案1】:

    只需简单地将 not ! 运算符(也称为空安全上的 bang 运算符)放在开始

    void main() {
      String myString = 'Dart';
    
    // just like i can do the following check
      myString.contains('a') ? print('validate') : print('does not validate');
    
    // I want to do another check here
      !myString.contains('@') ? print('does not validate') : print('validate');
    }
    
    

    【讨论】:

    • 我不知道有任何内置功能。
    • 好的!所以我几乎可以用这个bang 操作符来处理所有事情
    • dart bool check = false; !check ? print('getting the hang of it') : print('not yet');
    猜你喜欢
    • 2011-11-09
    • 2013-05-18
    • 1970-01-01
    • 2021-12-20
    • 1970-01-01
    • 2011-03-29
    • 2013-10-26
    • 2014-11-22
    • 2013-02-05
    相关资源
    最近更新 更多