I have this String :
String myStr = "[email protected]"
I want to get just the "something.bad" from myStr ?
I have this String :
String myStr = "[email protected]"
I want to get just the "something.bad" from myStr ?
You just need to use substring having found the right index to chop at:
int index = myStr.indexOf('@');
// TODO: work out what to do if index == -1
String firstPart = myStr.substring(0, index);
EDIT: Fairly obviously, the above takes the substring before the first @. If you want the substring before the last @ you would write:
int index = myStr.lastIndexOf('@');
// TODO: work out what to do if index == -1
String firstPart = myStr.substring(0, index);