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.1k Golang : Oanda bot with Telegram and RSI example
+13.5k Golang : Execute function at intervals or after some delay
+4.9k CodeIgniter/PHP : Remove empty lines above RSS or ATOM xml tag
+4.7k Golang : Configure crontab to poll every two minutes 8am to 6pm Monday to Friday
+8.7k Golang : Detect number of faces or vehicles in a photo
+17.1k Golang : Logging with logrus
+30.6k Golang : Validate email address with regular expression
+7k Golang : HttpRouter multiplexer routing example
+6k Golang : How to iterate a slice without using for loop?
+14.1k Golang : How to login and logout with JWT example
+7.2k How to show different content from website server when AdBlock is detected?