We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I am a newb to processing and have migrated from LiveCode. Just a quick question, not asking for a spoonfeed, just a general idea I should be looking at. The string contains PING and I am trying to replace it with PONG.
Many Thanks Guys!!
Matt.
Answers
Hey there. Well first you have to set your indicator. When do you want the string to change from Ping To Pong? Afterwards, say it's after a mousePressed. Then you would just do this:
Or if you want to permanently change it to Pong after mouse clicked....
Or if you want to make it happen after a certain amount of time:
after 3 seconds in this case.
So basically its all about resetting the initial value of your String variable. Hope it helps!
~TW7 :D
Thanks for your reply!! I meant to say that PING is among the characters of a string and i am trying to replace it in the string with PONG.
Many Thanks,
Matthew.
http://docs.Oracle.com/javase/8/docs/api/java/lang/String.html#replace-java.lang.CharSequence-java.lang.CharSequence-
use str.indexOf("Ping") to find where "Ping" starts, then concatenate a new string from the bits before, the word Pong & the bits after.
Oh, hey there yes, the replies that were given are both what you're looking for, PingOrPong.indexOf is what you need. Sorry about missing the point, but i'm glad it got fixed.
Thanks GoToLoop, that's much easier.
replace() will only do the first. replaceAll() will do all instances, should that be what you need.
Java naming conventions would use pingOrPong here. Classes start with an uppercase letter, members with a lowercase letter
Alas! Please read the link before stating that: L-)
http://docs.Oracle.com/javase/8/docs/api/java/lang/String.html#replace-java.lang.CharSequence-java.lang.CharSequence-