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?
You can achieve this with RegExp:
final output = string.replaceAll(RegExp(r"[24]"),'0');
[24] matches any character that is either 2 or 4.
RegExp(r"[$variable 4]", '0')RegExp("[${variable}4]", '0'). I mean the r is just denoting a raw string here. You are quite new to this site, so maybe check the rules here. Changing the question is highly discouraged, as this makes the answers and efforts potentially useless or inappropriate. Better to ask a new question.This works
void main() {
var string = '12345';
string = string.replaceAll('2', "0");
string = string.replaceAll('4', "0");
print(string);
}