Golang : How to get username from email address
Just need a simple solution to extract the username from a given email address. The code below uses strings.Split()
function to split an email address in between the @
symbol and we take the position 0
from the resulting slice to get the username
Here you go!
package main
import (
"fmt"
"strings"
)
func main() {
username := strings.Split("iamspammer@gmail.com", "@")
fmt.Printf("%q\n", username[0])
}
Output:
"iamspammer"
Hope this helps and happy coding!
See also : Golang : Chunk split or divide a string into smaller chunk example
By Adam Ng
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+21.1k Golang : untar or extract tar ball archive example
+2.8k Java : Random alphabets, alpha-numeric or numbers only string generator
+10.3k Golang : Display a text file line by line with line number example
+4.1k Python : Convert(cast) bytes to string example
+13.6k Golang : Missing Bazaar command
+10.6k Golang : Setup API server or gateway with Caddy and http.ListenAndServe() function example
+12.1k Golang : Read from buffered reader until specific number of bytes
+13.2k Golang : Reset buffer example
+11k Golang : Encrypt and decrypt data with x509 crypto
+5.9k Swift : substringWithRange() function example
+6.6k Gogland : Single File versus Go Application Run Configurations
+4.9k Golang : List all packages and search for certain package