Catching incidence of a character in a string
in
Programming Questions
•
1 year ago
I have this baffling problem. I read a text file into an array and I need to identify lines that start with a specific character and only process those lines. I can isolate the leftmost character and display it, but my IF statement condition doesn't trap that line. I've searched extensively and can't identify the issue. I'm hoping someone can eyeball and spot/correct my error.
Here is my code:
- for ( int i=0; i<lines.length; i++){ // cycle through the file line at a time
- println("line "+i + " : " +lines[i]); // verify the line number and text of the line - all lines are printing fine
- println(lines[i].substring(0,1)); // This prints the left-most character including the character wanted
- if (lines[i].substring(0,1)=="S") { // Even though the previous line displays the character "S" this conditional // statement doesn't catch it and is ignored
- // code to process line starting with "S"
- }
- }
Also, is there a Processing equivalent for the VB "left$" function (apart from what I'm using above)?
Thanks in advance.
1