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
+7.5k Golang : Progress bar with ∎ character
+17.7k Golang : Get RGBA values of each image pixel
+11.1k Golang : Forwarding a local port to a remote server example
+14k Golang : Get query string value on a POST request
+16.5k Golang : Get all upper case or lower case characters from string example
+6.7k Golang : Get today's weekday name and calculate target day distance example
+4.6k Unix/Linux/MacOSx : Get local IP address
+6.9k Golang : Multiplexer with net/http and map
+8.2k Golang : Find correlation coefficient example
+29.5k error: trying to remove "yum", which is protected
+3.6k Linux/MacOSX : Search and delete files by extension
+4.7k Linux : Disable and enable IPv4 forwarding