Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to test if a certain String containg another String? 2

Status
Not open for further replies.

thelordoftherings

Programmer
May 16, 2004
616
IL
Hello,

I have a String at this format: 1,2,3,4...
I would like to test if this String contains a certain int inside it. How can I do it without splitting the String to an Array by "," and go over it each time I want to check? Can someone please show me how to do it in regexp?
 
You could do something like the following:

String myString = "1,2,3,4";
int myNumber=2;
boolean myBoolean = myString.indexOf(valueOf(myNumber)) > 0;

if myBoolean is true then the number is in the string.
 
Or :

Code:
if (stringOne.indexOf(stringTwo) != -1) {
   // stringTwo is within stringOne
} else {
   // stringTwo is not within stringOne
}


--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top