Last active
November 26, 2021 08:30
-
-
Save iqfareez/ef5cc810748f64cb8033b0a415889ab3 to your computer and use it in GitHub Desktop.
IIUM Course Code String formatter in Dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
https://dartpad.dev/?id=ef5cc810748f64cb8033b0a415889ab3&null_safety=true