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