INSTR

Hi, IS there any function in java to check if a particular string is present in sentence.....supposing in the sentence ...."helli i am giddy" or " i am giddy aint i?" ....how can i check if giddy is present or not?ThanksVivek
[253 byte] By [vivek.shankara] at [2007-10-2 5:46:17]
# 1
Look at the methods in String's API docs. http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html
targaryena at 2007-7-16 1:56:06 > top of Java-index,Java Essentials,New To Java...
# 2
indexOf method in String API
kilyasa at 2007-7-16 1:56:06 > top of Java-index,Java Essentials,New To Java...
# 3
Thanks a lot!!containspublic boolean contains(CharSequence s),....IS this the function that does the trick?ThanksVivek
vivek.shankara at 2007-7-16 1:56:06 > top of Java-index,Java Essentials,New To Java...
# 4
> IS this the function that does the trick?Try it out. Give it a spin. Take it for a test drive. Give it a whirl. Knock yourself out. Etc.
yawmarka at 2007-7-16 1:56:06 > top of Java-index,Java Essentials,New To Java...
# 5

I prefer

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.

kilyasa at 2007-7-16 1:56:06 > top of Java-index,Java Essentials,New To Java...
# 6
THANKS A LOT!!I'll now Try it out. Give it a spin. Take it for a test drive. Give it a whirl. Knock MYSELF OUT :-Dregardsvivek
vivek.shankara at 2007-7-16 1:56:06 > top of Java-index,Java Essentials,New To Java...