indexOf doesn't match the exact string?

gokulraj
Giga Expert

Hi team,

I have a requirement to get the exact string comparison results.

if my condition is like [ if (emailTo.indexOf("networkoperation@test.com") != -1) ]

it will also satisfy the conditions if the email To contains like the following("operation@test.com")  

How to find the exact string matching?

18 REPLIES 18

Hi Harshvardhan,

I have tested your script it is working fine if the Email To contains only one recipients,

but it fails when more than one recipients in Email To condition,

Ex,

 

var emails='networkoperation@test.com , operation@test.com ';
if (emails.startsWith("operation@test.com"))
{

gs.print('hello');
}
else
{
gs.print('not hello');
}

It is executing the else part.

ok then in this scenario here we go 

 

var emails=["networkoperation@test.com","operation@test.com"];
var temp=0;
for (var i=0; i<emails.length;i++)
{


gs.print(emails[i]);
if(emails[i] === "harsh@test.com"){  // mention the email you want to compare here
temp = true;
break;}
else
{
temp= false;
}
}
if (temp) 
{
gs.print('hello');
}
else
{
gs.print('not hello');
}
//gs.print(temp);

have you tried this? i tested on my pdi and this will also fulfill your requirement.

rad2
Mega Sage

you might try to use .match() method along with regex to get the string that matches the expression

SaiRaviKiran Ak
Giga Guru

Try email.to.indexOf("networkoperation@test.com")!=-1