We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I want to tjek if the first letter in the test.txt file is "t". Why does this not work?:
String lines[] = loadStrings("test.txt");
println(lines[0]);
String letter = lines[0].substring(1, 2);
println(letter);
if(letter == "t"){
print("first letter is t!");
}else{
print("first letter is not t!");
}
The console says:
ttt-test
t
first letter is not t!
Answers
Do not compare strings for equality with == Use .equals()
Example:
there's a startsWith method on String that does this...
Besides substring() + equals(), and startsWith(), given you're only interested in checking out 1
char
within a String, you can use its charAt() method too: O:-)https://Processing.org/reference/String_charAt_.html
https://Processing.org/reference/char.html