formattazione testo da e verso json
This commit is contained in:
22
lib/core/utils/string_extensions.dart
Normal file
22
lib/core/utils/string_extensions.dart
Normal 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(' ');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user