Skip to content

Instantly share code, notes, and snippets.

@iqfareez
Last active November 26, 2021 08:30
Show Gist options
  • Save iqfareez/ef5cc810748f64cb8033b0a415889ab3 to your computer and use it in GitHub Desktop.
Save iqfareez/ef5cc810748f64cb8033b0a415889ab3 to your computer and use it in GitHub Desktop.
IIUM Course Code String formatter in Dart
void main(List<String> args) {
// examples
var courseCodes = [
'MCTE2333',
'LAW4510',
'CCUB 3921',
'LC 2014',
'TQB 1011M',
'ahbs2317'
];
for (var course in courseCodes) {
var i = course.indexOf(RegExp(r'[^A-Za-z]')); // get the index
var j = course.substring(0, i); // extract the first half
var k = course.substring(i).trim(); // extract the others
var formatted = '$j $k'.toUpperCase(); // combine & capitalize
print(formatted);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment