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.8k Golang : Get final balance from bit coin address example
+27.8k Golang : Get first few and last few characters from string
+6.1k Golang : Validate credit card example
+24.4k Golang : How to write CSV data to file
+12k Golang : How to get a user home directory path?
+5.8k Golang : Get expvar(export variables) to work with multiplexer
+8.4k Golang : Launch Mac OS X Preview (or other OS) application from your program example
+17.4k Golang : Set, Get and List environment variables
+48.7k Golang : Disable security check for HTTPS(SSL) with bad or expired certificate
+12.4k Golang : Convert spaces to tabs and back to spaces example
+36.5k Golang : Comparing date or timestamp
+14.7k Golang : Generate universally unique identifier(UUID) example