formattazione testo da e verso json

This commit is contained in:
2026-04-13 10:37:12 +02:00
parent 55b0a0839d
commit d72b329a13
4 changed files with 34 additions and 9 deletions

View File

@@ -0,0 +1,22 @@
extension MyStringExtensions on String? {
// Gestiamo anche il nullable per sicurezza
String myFormat() {
if (this == null || this!.trim().isEmpty) return '';
return this!
.trim()
.toLowerCase()
.split(' ')
.where((word) => word.isNotEmpty) // Evita problemi con doppi spazi
.map((word) {
if (word.contains('iphone') || word.contains('ipad')) {
return word.replaceFirst('ip', 'iP');
}
if (word.contains('imac')) {
return word.replaceFirst('im', 'iM');
}
return word[0].toUpperCase() + word.substring(1);
})
.join(' ');
}
}