Spliting Domain out from email address.

Hello,

I have the following email addresses:

michael.help@imlost.com
sahar.cool@insurance.com


I need to get the domain (ie. insurance.com) split off the right side because I need to write an if statement after this looking something like the following.

For example....

if(domain == null) ||(domain == "insurance.com")
{
"Employee"
}
else
{
"Other"
}
Michael FranzCFOAsked:
Who is Participating?
 
Rainer JeschorCommented:
Hi,
alternative way:
var testaddress = "john@doe.com";
var domain = testaddress.split("@")[1];

Open in new window

0
 
Radek BaranowskiFull-stack Java DeveloperCommented:
String s="some.email@somedomain.com";
int indexOfAt= s.indexOf('@');
String domain= s.substring(indexOfAt+1);
if(domain == null) ||(domain == "somedomain.com")
{
"Employee"
}
else
{
"Other"
}

Open in new window

0
 
Michael FranzCFOAuthor Commented:
I'm getting an error....I cut the IF off for the time being...


String s="some.email@somedomain.com";
int indexOfAt= s.indexOf('@');
String domain= s.substring(indexOfAt+1);

missing; before statement, line 28: String s=
0
 
Michael FranzCFOAuthor Commented:
AWESOME!!!! Yea thank you. Easy and it works!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.