I'm trying to trim the @domain.xxx from email address leaving just the username. I'm not sure how to dynamically select the @ position and everything to the right of it. Could someone please provide an example of how to do this? The trim code below is where I'm lost.
email = "[email protected]"
email....(trim code);
email.replace(email, "");
To find:
int index = string.indexOf('@');
To replace:
email = email.substring(0, index);
To summarize:
email = "[email protected]";
int index = email.indexOf('@');
email = email.substring(0,index);
Another approach is to split an email on a nickname and on a domain. Look at javadoc
There is a code example:
String email = "[email protected]";
String[] parts = email.split('@');
// now parts[0] contains "example"
// and parts[1] contains "domain.com"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With