Solved

How to check if a string contains another string

Posted on 2008-10-03
5
781 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

706 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now