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.2k Javascript : Get operating system and browser information
+8.3k Golang : Scramble and unscramble text message by randomly replacing words
+8.5k Golang : ffmpeg with os/exec.Command() returns non-zero status
+10.7k Linux : How to install driver for 600Mbps Dual Band Wifi USB Adapter
+7k Golang : Get all countries phone codes
+3.9k Golang : Calculate a pip value and distance to target profit example
+5.4k CodeIgniter : form input set_value cause " to become & quot
+12.2k Golang : Convert(cast) int to int64
+11.9k Android Studio : Password input and reveal password example
+12.4k Golang : Get constant name from value
+14.2k Golang : How to add color to string?
+9.6k Golang : How to transmit update file to client by HTTP request example