Solved

How to check if a string contains another string

Posted on 2008-10-03
5
785 Views
Last Modified: 2008-12-09
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
Comment
Question by:aswam1975
  • 2
5 Comments
 
LVL 9

Expert Comment

by:brunoguimaraes
ID: 22637348
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
 

Author Comment

by:aswam1975
ID: 22637999
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
 
LVL 9

Accepted Solution

by:
brunoguimaraes earned 40 total points
ID: 22649217
Same thing.
if (errorStr.indexOf("took longer than alloted time") != -1) {
   // do stuff
}

Open in new window

0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Windows 10 IE Certificate Issue 10 51
mysql jsp example issue 32 53
Need Help! Getting a syntax error and don't understand why 3 31
Coding for the first time 9 37
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question