Author |
Message |
Donny
|
Posted: 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? |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Tony
![](http://wiki.compsci.ca/images/f/f4/OniTony.gif)
|
|
|
|
![](images/spacer.gif) |
Donny
|
Posted: 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 &&.. |
|
|
|
|
![](images/spacer.gif) |
Tony
![](http://wiki.compsci.ca/images/f/f4/OniTony.gif)
|
Posted: 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. |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
![](images/spacer.gif) |
Donny
|
Posted: 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? |
|
|
|
|
![](images/spacer.gif) |
SmokeMonster
|
|
|
|
![](images/spacer.gif) |
Insectoid
![](http://compsci.ca/v3/uploads/user_avatars/13760332514cbd0ce972eaa.jpg)
|
Posted: 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. |
|
|
|
|
![](images/spacer.gif) |
Tony
![](http://wiki.compsci.ca/images/f/f4/OniTony.gif)
|
Posted: 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. |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
|