samarth
samarth

Reputation: 65

Flutter | How to check if String does not contain a substring or a character

I'm learning Flutter/Dart and there is this check that i want to perform - to validate that a user who has entered an email should contain @ in it

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')

Can someone suggest is there any inbuilt function to do such a thing.

Upvotes: 5

Views: 8425

Answers (1)

Md. Yeasin Sheikh
Md. Yeasin Sheikh

Reputation: 63659

Just simply put not ! operator (also known as bang operator on null-safety) on start

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');
}

Upvotes: 9

Related Questions