We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hey everyone,
I have recently started using Processing and I love it! I do not have so much programming background, so I would be happy if you could help me from time to time :)
Right now, I have this code, which does not work as expected:
String varText = "012345";
String varSubstring = varText.substring(2, 3);
println(varSubstring); // This prints 2. So far, so good, but
// ... this does never evaluate to TRUE:
if (varSubstring == "2") {
println("It is 2!");
} else {
println("Oh no, it did not work!");
}
Does anyone have an idea how I could make this work?
Thank you very much!
Sebastian
Answers
https://forum.Processing.org/two/discussion/15473/readme-how-to-format-code-and-text
Use equals() in order to compare strings: https://Processing.org/reference/String_equals_.html
can't test this for you at present but look here: https://processing.org/reference/String_equals_.html
try
if (varSubstring.equals("2") == true) {
Alternatively, go w/
switch () / case: / break / default:
: *-:)https://Processing.org/reference/switch.html
https://Processing.org/reference/case.html
https://Processing.org/reference/break.html
https://Processing.org/reference/default.html
Thanks a lot, guys, for the really helpful answers!