Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to check if a string contains another string

Posted on 2008-10-03
5
Medium Priority
?
790 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 160 total points
ID: 22649217
Same thing.
if (errorStr.indexOf("took longer than alloted time") != -1) {
   // do stuff
}

Open in new window

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses

610 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