Created
June 9, 2021 18:19
-
-
Save filipedfs/74022bb2006758b41053eee5858e03d7 to your computer and use it in GitHub Desktop.
Format CPF
This file contains hidden or 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() { | |
| final String text = '11122233344'; | |
| print(maskText(text, 'CPF')); | |
| } | |
| String maskText(String text, String type) { | |
| // Format CPF. | |
| if (type == 'CPF') { | |
| final List<String> chars = text.split(''); | |
| chars.insert(3, '.'); | |
| chars.insert(7, '.'); | |
| chars.insert(11, '-'); | |
| return chars.join(''); | |
| } | |
| // Other number types. | |
| else { | |
| return text; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment