Computer Science Canada String does not contain? |
Author: | Donny [ 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? |
Author: | Tony [ Tue Apr 19, 2011 5:22 pm ] |
Post subject: | RE:String does not contain? |
http://en.wikipedia.org/wiki/De_Morgan's_laws |
Author: | Donny [ 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 &&.. |
Author: | Tony [ 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
You could also just negate the entire statement
P.S. figuring out how stuff works well enough to write good programs requires a lot of reading. |
Author: | Donny [ 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? |
Author: | SmokeMonster [ 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 |
Author: | Insectoid [ 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. |
Author: | Tony [ 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. |