toPascalCase static method
Converts a string to Pascal case.
The method takes a string, removes any non-alphanumeric characters, splits the string into words, and then joins them back together with the first letter of each word capitalized.
Implementation
static String toPascalCase(String s) {
// Remove any non-alphanumeric characters and split the string into words
List<String> words =
s.replaceAll(RegExp(r'[^A-Za-z0-9\s]'), '').trim().split(' ');
String result = '';
// Join the words back together with the first letter of each word capitalized
for (var word in words) {
result += word[0].toUpperCase() + word.substring(1).toLowerCase();
}
return result;
}