Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 String does not contain?
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Donny




PostPosted: Tue Apr 19, 2011 5:19 pm   Post subject: String does not contain?

if (button == right && msg.contains(k));

I have this in an if statement, now i want something that will check for anything but that, how can this be achieved?
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Tue Apr 19, 2011 5:22 pm   Post subject: RE:String does not contain?

http://en.wikipedia.org/wiki/De_Morgan's_laws
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Donny




PostPosted: Tue Apr 19, 2011 5:26 pm   Post subject: RE:String does not contain?

This isn't a school project or anything so a little actual advice would help, I don't feel like reading this whole article. It doesn't even have code snippets.


EDIT: sorry for my rudeness and stupidity, i'm ill and not in a good mood, i just figured it out.. != infront instead of &&..
Tony




PostPosted: Tue Apr 19, 2011 5:33 pm   Post subject: RE:String does not contain?

It's was like the very first thing on the page
Quote:

NOT (P AND Q) = (NOT P) OR (NOT Q)

P := button == right
Q := msg.contains(k)

so you want
code:

if ( button != right || !msg.contains(k) )


You could also just negate the entire statement
code:

if (!(button == right && msg.contains(k)))


P.S. figuring out how stuff works well enough to write good programs requires a lot of reading.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Donny




PostPosted: Tue Apr 19, 2011 5:37 pm   Post subject: RE:String does not contain?

Ya, i figured as much I just wasn't in the mood, and the way I did it didn't work out, instead of && i put != when I didn't know you could just put ! to negate something, and it would move my chars (over a network) in opposite directions somehow lol


EDIT: Also, how can i trim strings? I want to take 59021 : right and trim it down to just 59021, do you know how to do this?
SmokeMonster




PostPosted: Thu Apr 21, 2011 12:02 am   Post subject: Re: String does not contain?

Use the trim function. http://download.oracle.com/javase/1.3/docs/api/java/lang/String.html#trim%28%29
Insectoid




PostPosted: Thu Apr 21, 2011 9:45 am   Post subject: RE:String does not contain?

That's not exactly what he was going for.

Use a string tokenizer. I dunno how it works in Java, but it certainly exists. Use a colon (Or, a space followed by a colon) as the delimiter and take the first token.
Tony




PostPosted: Thu Apr 21, 2011 11:02 am   Post subject: Re: RE:String does not contain?

Insectoid @ Thu Apr 21, 2011 9:45 am wrote:
Use a string tokenizer. I dunno how it works in Java

Java's Scanner class can take a custom delimiter and tokenize the input.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Sponsor
Sponsor
Sponsor
sponsor
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 8 Posts ]
Jump to:   


Style:  
Search: