Skip to content

Instantly share code, notes, and snippets.

@lucivaldo
Last active December 31, 2024 04:49
Show Gist options
  • Select an option

  • Save lucivaldo/25c8a395359b9fb20d4c93aaa48cd12c to your computer and use it in GitHub Desktop.

Select an option

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 = 'Fulano de Tal';
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