Skip to content

Instantly share code, notes, and snippets.

@lucivaldo
Created June 29, 2020 23:18
Show Gist options
  • Save lucivaldo/25c8a395359b9fb20d4c93aaa48cd12c to your computer and use it in GitHub Desktop.
Save lucivaldo/25c8a395359b9fb20d4c93aaa48cd12c to your computer and use it in GitHub Desktop.
Função para obter as letras inicias do nome e sobrenome
void main() {
var name = 'Lucivaldo Castro Castelo Branco';
print(twoLetters(name));
}
String twoLetters(String name) {
if (name.trim().isEmpty) return null;
var nameSplited = name.trim().replaceAll(RegExp(r'\s+', ), ' ').split(' ');
var letters = nameSplited.first[0];
if (nameSplited.length > 1) {
letters = nameSplited.sublist(0, 2).reduce((value, element) {
return value[0] + element[0];
});
}
return letters;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment