Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
loadnycon
Posts: 18
Registered: ‎02-03-2010
My Device: Blackberry Storm - 9570
My Carrier: Tim
Accepted Solution

String.contains()

Hi!

Im trying to do a search, RIM SDK dont have String.contains().

I need to do anything like this:

 

i have a list with many names like Jonh Man, Sesame Road, Mary Jane...

 

The user inputs: ROAD = userInput

 

i return all words with road, like:

 

Sesame Road myWord[0]

Long Road myWord[1]

Road Test ...

St. Street Road..

 

how i can compare user input with my vector words?

 

if i had contains, i would do something like this... 

 

if(userInput.contains(myWorld[i])){

output....

}

 

Thx...

Please use plain text.
Developer
ankit2grover
Posts: 159
Registered: ‎08-19-2008
My Device: Not Specified

Re: String.contains()

Use string.indexOf("word",0).............if it returns > 0 then u can add it to vector myWord otherwise not..............

Please use plain text.
Developer
loadnycon
Posts: 18
Registered: ‎02-03-2010
My Device: Blackberry Storm - 9570
My Carrier: Tim

Re: String.contains()

thx, that works XD

Please use plain text.
Developer
simon_hain
Posts: 16,017
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: String.contains()

only as a sidenote, use >-1. 0 is a valid index.

----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Developer
rihan007
Posts: 455
Registered: ‎01-14-2009
My Device: Apple iPhone 3GS 16GB

Re: String.contains()

Feel free to use this method

 

 

   public static boolean contains(String fullString, String searchedString) {
                try {
                        if (fullString.toLowerCase().indexOf(searchedString.toLowerCase()) != -1)
                                return true;
                } catch (Exception e) {
                        return false;
                }
                return false;
        }

 

 

Please use plain text.