We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › how to write for a string match anyone in a text
Page Index Toggle Pages: 1
how to write for a string match anyone in a text (Read 459 times)
how to write for a string match anyone in a text
Nov 3rd, 2007, 5:18pm
 
As string with syntax of 'equals', which only match the exact wordings e.g

String str1 = "CCCP";
String str2 = "CCCP";
// Tests to see if str1 is equal to str2
if(str1.equals(str2) == true) {
...

I wonder if there is function which match any of the wordings e.g

String str1 ="i am so happy today"; // whole sentence
String input ="happy"; //specific search key words

if input match/exist in any of str1 => return true
??

anyone can help? thanks
Re: how to write for a string match anyone in a te
Reply #1 - Nov 3rd, 2007, 5:40pm
 
You can use the indexOf method with strings as well as single characters, so the following should work:
Code:
if(str1.indexOf(input)>=0))
{
//do something
}
Re: how to write for a string match anyone in a te
Reply #2 - Nov 3rd, 2007, 7:52pm
 
got it...thanks alot & it works.
Page Index Toggle Pages: 1