Find space in string

I have a sentece as a string, and I want to print in on the screen, each word in different line,
but when I try to comapre if the current char is space,
I get this error:

cannot convert from char to String, regarding the line
String curr = s.charAt(l);

String s = "What a wonderfull word";
  
  int x=width/2;
  int y = height/2;
  
  int l=0;
  
    String space=" ";
    String curr = s.charAt(l);

  while (s.charAt(l).equals(space) == false)
  
  {
   text(s.charAt(l),x,y);
   x-=text_size;
   l++;
  }
  y+=30;
  l++;
  
  PGraphicsPDF pdf = (PGraphicsPDF) g;
  pdf.nextPage();
  
  }

println("finished");
 exit();
}```

What am I missing?

final char space = ' ';

Method String::charAt() returns a char, not a String:

while (s.charAt(l) != space) {

3 Likes

It’s wonderful with only one l

There are lots of ways, but see also split command

Occasionally I will send a private message as a courtesy when I spot a spelling error.

We all make mistakes including spelling errors.

I have a few as well!

What a wonderful world!

:)

Thanks for correcting.
:slight_smile:

The real sentence is acutally in Hebrew,
The sentence I wrote was just an example

2 Likes

Hello,

Look up reference to understand splitTokens().
I am using an “enhanced for loop”.

:)