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
+5.5k Golang : Display advertisement images or strings on random order
+10.9k Golang : Create Temporary File
+6.4k CodeIgniter : form input set_value cause " to become & quot
+5.2k Golang : Convert lines of string into list for delete and insert operation
+37.7k Golang : Comparing date or timestamp
+4.6k Javascript : Detect when console is activated and do something about it
+11.2k Golang : Fix - does not implement sort.Interface (missing Len method)
+4.7k Unix/Linux : How to pipe/save output of a command to file?
+13.1k Golang : List objects in AWS S3 bucket
+5.6k PHP : Convert CSV to JSON with YQL example
+16.7k Golang : Gzip file example
+8.8k Golang : Accept any number of function arguments with three dots(...)