• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 792
  • Last Modified:

How to check if a string contains another string

I can I check if a string contains another string in it.?
I would like to check if the string "time out" is contained in my string.
For this I tried:
if(errorStr.indexOf("timed out") != -1)
but it does not work
Any help would be appreciated
0
aswam1975
Asked:
aswam1975
  • 2
1 Solution
 
brunoguimaraesCommented:
Actually, the way you tried is the right way. Just remember it is case sensitive. If your string is "Connection Timed Out" and you look for "timed out", it will find nothing.
0
 
aswam1975Author Commented:
Thanks- I learnt that the string would be
"took longer than alloted time".
I did the same, but it isn't working.Most examples that I have seen ,use a single word like "time" not an entire string.
How can I check if "took longer than alloted time". is contained?
0
 
brunoguimaraesCommented:
Same thing.
if (errorStr.indexOf("took longer than alloted time") != -1) {
   // do stuff
}

Open in new window

0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now