Dart find the capital word in a given String
How can I write a code that finds capital words in a given string in dart
for example
String name ='deryaKimlonLeo'
//output='KL'
Solution 1:
Hmmm try this using pattern if you only want to get only the big letter then try this
String name ='deryaKimlonLeo';
print(name.replaceAll(RegExp(r'[a-z]'),""));
//Output you wanted will be
// KL
try this on dart pad it works
Solution 2:
A basic way of doing this is like
void main() {
String name = 'deryaKimlonLeo';
String result = '';
for (int i = 0; i < name.length; i++) {
if (name.codeUnitAt(i) <= 90 && name.codeUnitAt(i) >= 65) {
result += name[i];
}
}
print(result);
}
More about ASCII and codeUnitAt.