<Flutter Dart>文字列の検索・置換

文字列の検索・置換

// 元の文字列
String greeting = 'My name is Bob.';

// Bobを含むか
bool isBob = greeting.contains('Bob');
// Tomを含むか
bool isTom = greeting.contains('Tom');

print(greeting);
print(isBob);
print(isTom);

// output
// My name is Bob.
// true
// false

// 元の文字列のBobをTomに置換
greeting = greeting.replaceAll('Bob', 'Tom');
print(greeting);
print(isBob);
print(isTom);

// output
// My name is Tom.
// true
// false