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
+4.7k Golang : ROT32768 (rotate by 0x80) UTF-8 strings example
+6.1k Javascript : How to get JSON data from another website with JQuery or Ajax ?
+17.4k Golang : Example for RSA package functions
+10.6k Golang : Verify Linux user password again before executing a program example
+27.6k Golang : Saving(serializing) and reading file with GOB
+5.3k Golang : Experimental emojis or emoticons icons programming language
+4.6k Clean up Visual Studio For Mac installation failed disk full problem
+10.2k CodeIgniter : How to check if a session exist in PHP?
+9.8k PHP : Convert(cast) bigInt to string
+16.3k Google Chrome : Your connection to website is encrypted with obsolete cryptography
+4.6k Golang : Stop goroutine without channel
+13.1k Golang : Recombine chunked files example