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
+15.2k Golang : Upload/Receive file progress indicator
+3.5k Golang : Check if a word is countable or not
+4.7k Apt-get to install and uninstall Golang
+16.9k Golang : Check if directory exist and create if does not exist
+26.8k Golang : Converting a negative number to positive number
+9.4k Golang : Convert decimal number(integer) to IPv4 address
+19k Golang : Match strings by wildcard patterns with filepath.Match() function
+13.7k Golang : convert string or integer to big.Int type
+8.1k Javascript : Read/parse JSON data from HTTP response
+10.6k Golang : Get user input until a command or receive a word to stop
+6.8k Golang : Combine slices but preserve order example
+5k Golang : Check if password length meet the requirement