dcsimg
How to check whether a String contains a string iam searching for ..?
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Anonymous
Posted On:   Monday, January 6, 2003 12:51 AM

Hi Friends ..


I have a requirement like ..

I want to check whether a String contains a string iam searching for ..?


For ex. iam having a String A = "THIS IS TEST";
i want to check whether String A contains "THIS".


Can anyone help me in getting me the easy way to achieve this ..


Thanks in advance,


Chimbu

Re: How to check whether a String contains a string iam searching for ..?

Posted By:   Eelco_Cramer  
Posted On:   Monday, January 6, 2003 02:23 AM

Taken from the Javadoc:


String.indexOf


public int indexOf(String str)


Returns the index within this string of the first occurrence of the specified substring. The integer returned is the smallest value k such that:



this.startsWith(str, k)


is true.


Parameters:
str - any string.
Returns:
if the string argument occurs as a substring within this object, then the index of the first character of the first such substring is returned; if it does not occur as a substring, -1 is returned.
Throws:
NullPointerException - if str is null.

About | Sitemap | Contact