# Find space in string

**URL:** <https://discourse.processing.org/t/find-space-in-string/33760>\
**Category:** Beginners\
**Created:** [November 25, 2021, 10:43pm UTC](https://discourse.processing.org/t/find-space-in-string/33760 "2021-11-25T22:43:57Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![yalaniv](https://avatars.discourse-cdn.com/v4/letter/y/7993a0/32.png) [@yalaniv](https://discourse.processing.org/u/yalaniv)\
**Post date:** [November 25, 2021, 10:43pm UTC](https://discourse.processing.org/t/find-space-in-string/33760/1 "2021-11-25T22:43:58Z")

</div>

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);

````auto
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?
````

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [November 25, 2021, 10:48pm UTC](https://discourse.processing.org/t/find-space-in-string/33760/2 "2021-11-25T22:48:52Z")

</div>

> [@yalaniv](#):
>
> `String space = " ";`

`final char space = ' ';`

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

> **[charAt() / Reference](https://processing.org/reference/String_charAt_.html)**
>
> Returns the character at the specified index. An index ranges from 0 to the length of the string minus 1. The first character of the sequence is at index 0, the next at index 1, etc.

> **[char / Reference](https://processing.org/reference/char.html)**
>
> Datatype for characters, typographic symbols such as A, d, and $. A char stores letters and symbols in the Unicode format, a coding system developed to support a variety of world languages. Eac…

> [@yalaniv](#):
>
> `while (s.charAt(l).equals(space) == false) {`

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

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [November 26, 2021, 7:07pm UTC](https://discourse.processing.org/t/find-space-in-string/33760/3 "2021-11-26T19:07:46Z")

</div>

> [@yalaniv](#):
>
> `"What a wonderfull word";`

It’s wonderful with only one l

There are lots of ways, but see also split command

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [December 4, 2021, 12:34pm UTC](https://discourse.processing.org/t/find-space-in-string/33760/4 "2021-12-04T12:34:58Z")

</div>

> [@Chrisir](#):
>
> It’s wonderful with only one l

Occasionally I will send a _private message_ as a courtesy when I spot a spelling error.

> [@Mouse frustration!](https://discourse.processing.org/t/mouse-frustration/33789/5):
>
> That’s good when you use it in draw() to draw continuuesly.

We all make mistakes including spelling errors.

I have a few as well!

What a wonderful world!

`:)`

---

<div class="post-metadata">

**Author:** ![yalaniv](https://avatars.discourse-cdn.com/v4/letter/y/7993a0/32.png) [@yalaniv](https://discourse.processing.org/u/yalaniv)\
**Post date:** [December 4, 2021, 2:13pm UTC](https://discourse.processing.org/t/find-space-in-string/33760/5 "2021-12-04T14:13:27Z")

</div>

Thanks for correcting.  
🙂

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

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [December 4, 2021, 10:57pm UTC](https://discourse.processing.org/t/find-space-in-string/33760/6 "2021-12-04T22:57:08Z")

</div>

Hello,

> [@yalaniv](#):
>
> I want to print in on the screen, each word in different line

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/5/58d1aae15a98ba2e146ae86d3df99d8d0a4f9451.png)

Look up reference to understand `splitTokens()`.  
I am using an “[enhanced for loop](https://www.programiz.com/java-programming/enhanced-for-loop)”.

`:)`
