Solved

How to check if a string contains another string

Posted on 2008-10-03
5
786 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Custom Java Application connects to database: Which one of the 20? 4 54
DTD and JAVA versions 1 52
Java pass by reference 3 68
junit initializtion error 2 17
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This video teaches viewers about errors in exception handling.
Suggested Courses

742 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