Created
June 29, 2020 23:18
-
-
Save lucivaldo/25c8a395359b9fb20d4c93aaa48cd12c to your computer and use it in GitHub Desktop.
Função para obter as letras inicias do nome e sobrenome
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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