multiple static method
Replaces multiple occurrences of characters in the input string with corresponding replacements.
Parameters:
value
: The input string to perform replacements on.replacements
: A list of strings to replace matched characters with.regex
: A list of regular expressions to match characters for replacement.
Example:
String result = Replacement.multiple("Hello, World!", ["_", "+"], [" ", "!"]);
print(result); // Output: 'Hello+_World_'
Implementation
static String multiple(
String value,
List<String> replacements,
List<String> regex,
) {
final valid = Validator.isMatched(regex.length, replacements.length);
if (regex.isNotEmpty && valid) {
for (int index = 0; index < value.length; index++) {
value = value.replaceAll(regex[index], replacements[index]);
}
}
return value;
}