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 › ' if() ' with text
Page Index Toggle Pages: 1
' if() ' with text (Read 817 times)
' if() ' with text
Oct 31st, 2009, 7:18am
 
What am I doing wrong here? - I cant make an if statement that recognises text..? Thanks!

String type = getType();

if(type == "sym") {
    symCount = symCount + 1;
}else if(type == "rep"){
    repCount = repCount + 1;
}else if(type == "run"){
    runCount = runCount + 1;
}
Re: ' if() ' with text
Reply #1 - Oct 31st, 2009, 7:35am
 
hi

you have to use x.equals( y ) instead of x == y
when dealing with strings in a java or processing
Re: ' if() ' with text
Reply #2 - Oct 31st, 2009, 7:36am
 
You should read, or re-read, the String page.
Re: ' if() ' with text
Reply #3 - Oct 31st, 2009, 7:36am
 
i think the problem is the getType function; in java it returns a type, not what you're typing:)

try to look here
Re: ' if() ' with text
Reply #4 - Oct 31st, 2009, 7:37am
 
lol i was late:)
Re: ' if() ' with text
Reply #5 - Oct 31st, 2009, 7:40am
 
I am going to join this party with:

static Type getType(java.lang.String name)
         Find an Type with the given name, or create a new one.

probably not what you're after!

if (myString.equals("sometext")) as everyone has said, or do you want to test a string to see if it contains valid chars?
Re: ' if() ' with text
Reply #6 - Nov 1st, 2009, 11:14am
 
Thanks to all!
Page Index Toggle Pages: 1