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
+12.2k Golang : Listen and Serve on sub domain example
+9.9k Golang : Wait and sync.WaitGroup example
+14.2k Golang : Missing Bazaar command
+15.3k Golang : Get current time from the Internet time server(ntp) example
+11.6k Golang : Get remaining text such as id or filename after last segment in URL path
+12.5k Golang : Convert IPv4 address to packed 32-bit binary format
+4.4k Linux/MacOSX : How to symlink a file?
+6.2k Golang : Embedded or data bundling example
+8.8k Golang : Apply Histogram Equalization to color images
+11.7k Golang : Pagination with go-paginator configuration example
+22.4k Golang : Test file read write permission example
+8.7k Golang : Gonum standard normal random numbers example