Last active
May 1, 2019 03:25
-
-
Save iraniamir/9bf1fad346331e388eefd5c774bf0f6f to your computer and use it in GitHub Desktop.
Instagram, show summary email address
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
package main | |
import ( | |
"fmt" | |
"strings" | |
) | |
func main() { | |
fmt.Print(hideEmailAddress("[email protected]")) | |
} | |
func hideEmailAddress(email string) string { | |
components := strings.Split(email, "@") | |
username, domain := components[0], components[1] | |
firstCharacter, lastCharacter := string(username[0:1]), string(username[len(username)-1:]) | |
usernameLen := len(username) | |
stars := strings.Repeat("*", usernameLen-2) | |
return firstCharacter + stars + lastCharacter + "@" + domain | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
After reading
strings.Split
API and related logic around it, I think it is so better to usestrings.Index
. I improve my last suggestion with this one!