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!

String/substrings

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0

Hey everyone,

I have a quick question...

Is there a predefined method within the String class to see if a word exists within a word?

For example,

If a variable: fullString = "racecar";
and I want to find out if partString = "car" exists within stringExample...is this possible without specifying an exact index?

Basically I would like to know if there is a function that I can say

Does partString exist in fullString? --> true or false?

Any feedback is appreciated.

Thanks in advance,

-Jin

 
From String API:
Code:
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.
Wushutwist
 
hi,

I'v encountered such a question. In Java 1.4 Blta version, there are some functions support Regular Expression(RE) which can deal with this problem.
this link is helpful for RE.
You may also find out more new about Java 1.4 in
java.sun.com

Good luck.

duan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top