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("[email protected]", "@")
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
+11.4k Get form post value in Go
+16.1k Golang : Test floating point numbers not-a-number and infinite example
+9.2k Golang : Changing a RGBA image number of channels with OpenCV
+7.6k Golang : Regular Expression find string example
+11.8k Linux : How to install driver for 600Mbps Dual Band Wifi USB Adapter
+18.2k Golang : Example for RSA package functions
+10.1k Fix ERROR 1045 (28000): Access denied for user 'root'@'ip-address' (using password: YES)
+51.1k Golang : Check if item is in slice/array
+12.8k Golang : How to calculate the distance between two coordinates using Haversine formula
+17.7k Golang : Put UTF8 text on OpenCV video capture image frame
+5.1k Golang : How to deal with configuration data?
+4.8k Linux/Unix/MacOSX : Find out which application is listening to port 80 or use which IP version