Skip to content

Instantly share code, notes, and snippets.

@geektutor
Created May 7, 2020 18:23
Show Gist options
  • Save geektutor/d2925a89e4ded6d31a969072f3bb3d86 to your computer and use it in GitHub Desktop.
Save geektutor/d2925a89e4ded6d31a969072f3bb3d86 to your computer and use it in GitHub Desktop.
Day 7
void main() {
swapCase('Www.HackerRank.com');
swapCase('Dart2');
swapCase('HackerRank.com presents "Dart 2".');
}
swapCase(String text) {
var literalList = text.split("");
var output = [];
for (var i = 0; i < literalList.length; i++) {
if (literalList[i] == literalList[i].toUpperCase()) {
output.add(literalList[i].toLowerCase());
} else {
output.add(literalList[i].toUpperCase());
}
}
String output1 = output.join();
print(output1);
}
/*
You are given a string and your task is to swap cases. In other words, convert all lowercase letters to uppercase letters and vice versa.
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment