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
+18.2k Golang : Convert IPv4 address to decimal number(base 10) or integer
+14.5k Golang : Find network of an IP address
+17.1k Golang : XML to JSON example
+14.6k Android Studio : Use image as AlertDialog title with custom layout example
+9.1k Golang : Handle sub domain with Gin
+4.4k Linux/MacOSX : Search and delete files by extension
+15.5k Golang : Find location by IP address and display with Google Map
+18k Golang : Defer function inside init()
+17k Golang : Read integer from file into array
+9.5k Facebook : Getting the friends list with PHP return JSON format
+7k Golang : Levenshtein distance example
+5.5k How to check with curl if my website or the asset is gzipped ?