A Collection of Code Snippets in as Many Programming Languages as Possible
This project is maintained by TheRenegadeCoder
Welcome to the Duplicate Character Counter in Dart page! Here, you'll find the source code for this program as well as a description of how the program works.
//Issue 4974
void main(List<String> args){
const String error_message = "Usage: please provide a string";
if (args.isEmpty || args[0].isEmpty){
print(error_message);
return;
} // end of empty check
Map<String, int> frequency = {};
bool duplicate_not_found = true;
for (int i = 0; i < args[0].length; i ++){
String char = args[0][i];
if (RegExp(r'[a-zA-Z0-9]').hasMatch(char)) {
frequency[char] = (frequency[char] ?? 0) + 1;
}
} // end of checking duplicate characters
//either print all duplicate letters or set flag duplicate letters not found
frequency.forEach((char, count){
if (count > 1) {
duplicate_not_found = false; // at least 1 duplicate letter is found
print('$char: $count');
}
});
// print if no duplicate characters
if(duplicate_not_found == true){
print("No duplicate characters");
}
}
Duplicate Character Counter in Dart was written by:
If you see anything you'd like to change or update, please consider contributing.
No 'How to Implement the Solution' section available. Please consider contributing.
No 'How to Run the Solution' section available. Please consider contributing.