in java 9 we can simply convert camelCase to underscore like camel_case
String text = "camelCase";
Matcher m = Pattern.compile("(?<=[a-z])[A-Z]").matcher(text);
String result = m.replaceAll(match -> "_" + match.group().toLowerCase());
now my question is whats equivalent of this code in dart?
You can use RegExp and the method replaceAllMapped:
String text = 'camelCase';
final exp = RegExp('(?<=[a-z])[A-Z]');
String result = text.replaceAllMapped(exp, (m) => '_${m.group(0)}').toLowerCase();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With