Reputation: 28886
var string = '12345';
I want to replace 2
and 4
with 0
, so I tried:
var output = string.replaceAll('2, 4', '0') // doesn't work
I am not sure if I need to use RegExp
for this small stuff? Is there any other way to solve this?
Upvotes: 1
Views: 145
Reputation: 12673
This works
void main() {
var string = '12345';
string = string.replaceAll('2', "0");
string = string.replaceAll('4', "0");
print(string);
}
Upvotes: 1
Reputation: 25632
You can achieve this with RegExp
:
final output = string.replaceAll(RegExp(r"[24]"),'0');
[24]
matches any character that is either 2
or 4
.
Upvotes: 2