hello can you help me please what is the string method to be use when searching a keyword

that can be found in first, middle, end of the word...

example "CH"

this will search all names having this "CH"...can you help me what is the string method to use this...hoping for your positive responds...

Recommended Answers

All 8 Replies

Have a look at the contains(...) method in the String class (ps: in case you are worried, CharSequence is just an Interface implemented by all Strings)

To check whether a string starts or end with a particular pattern of strings u can use

startsWith(String prefix)
Tests if this string starts with the specified prefix.
boolean startsWith(String prefix, int toffset)
Tests if this string starts with the specified prefix beginning a specified index.

to check for string ending with a particular pattern

boolean endsWith(String suffix)
Tests if this string ends with the specified suffix.


To check in middle you have to use a substring function to extract the particular pattern and then compare it....

Hope it might help u a lil bit....

To check in middle you have to use a substring function to extract the particular pattern and then compare it....

Not true. Use contains(...)

u can check out all the string function here

http://java.sun.com/j2se/1.3/docs/api/java/lang/String.html

This link is to the Java 1.3 documentation, which is years out of date!
The language was very significantly updated in version 1.5.
Google your way to 1.5 or (even better) 1.6 docs.

Not true. Use contains(...)

hello thank you for the reply...okay i will try this method contains...thank you for helping me i will write again if i have doubt on this...more power to you...thank you again...

To check whether a string starts or end with a particular pattern of strings u can use

startsWith(String prefix)
Tests if this string starts with the specified prefix.
boolean startsWith(String prefix, int toffset)
Tests if this string starts with the specified prefix beginning a specified index.

to check for string ending with a particular pattern

boolean endsWith(String suffix)
Tests if this string ends with the specified suffix.


To check in middle you have to use a substring function to extract the particular pattern and then compare it....

Hope it might help u a lil bit....

hello sir thank you for the reply and for helping me...i will write again if i have doubt...more power to you sir...

Have a look at the contains(...) method in the String class (ps: in case you are worried, CharSequence is just an Interface implemented by all Strings)

Hello i tried the contains() and it works thank you for helping me...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.