My string messege contain the string either this:
var strMessage = "Plcc-failed|Score-passed|bankruptcy-passed|Years in Business
i.e. it contains a " | " symbol in it or this
var strmsg="fail".
I need a javascript function to check whether it contains a "fail" msg or " | " symbol.
How to write a javascript function for it.
Thanks in advance
Javascript function to check "|" symbol is present or not
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.

Abhay ShankerRank #375 · 6.7K reputationPosted Nov 26, 2013, 3:45 AM EST
var str="Plcc-failed|Score-passed|bankruptcy-passed|Years in Business";
var n=str.split("|");
var disp;
alert(pipeindex);
for(var i=0;i<4;i++)
{
if(i==0)
disp=n[i];
else
disp=disp+n[i];
alert(disp);
Ahmar HusainRank #1,312 · 1.3K reputationPosted Nov 26, 2013, 6:48 PM EST
if(strMessage.search('|')>=0)
{
alert("String contains |");
}
else if(strMessage=="fail)
{
alert("fail");
}
search method of javascript return the index of character searched in the string if the string doesnot contain the searched character it returns a negative integer in most cases it is -1.