# Is there any way to split a string into an array of characters?

**URL:** <https://discourse.processing.org/t/is-there-any-way-to-split-a-string-into-an-array-of-characters/19521>\
**Category:** Beginners\
**Created:** [April 8, 2020, 3:24am UTC](https://discourse.processing.org/t/is-there-any-way-to-split-a-string-into-an-array-of-characters/19521 "2020-04-08T03:24:08Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Math\_Machine](https://avatars.discourse-cdn.com/v4/letter/m/f14d63/32.png) [@Math\_Machine](https://discourse.processing.org/u/Math_Machine)\
**Post date:** [April 8, 2020, 3:24am UTC](https://discourse.processing.org/t/is-there-any-way-to-split-a-string-into-an-array-of-characters/19521/1 "2020-04-08T03:24:08Z")

</div>

Is there any way that I can split up a string into an array of its individual components? Like, for example, if I had the string “hello?”, is there any way I could convert that into an array in the form {“h”,“e”,“l”,“l”,“o”,"?"} ? I’m aware that there’s a function called split, but it only appears to work if there’s something separating each part. (so if a==“h-e-ll-o”, split(a,"-") will give you an array of the form {“h”,“e”,“ll”,“o”}). I’ve tried leaving the second parameter blank, but that wouldn’t compile, and I tried setting the string in that field to “”, and processing decided to have an angry nap. I’ve also tried looking into the splitTokens function, but it doesn’t really seem to be much different.

Is there any way I can split a string into its base components? Or is this just a lost cause?

---

<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:** [April 8, 2020, 3:32am UTC](https://discourse.processing.org/t/is-there-any-way-to-split-a-string-into-an-array-of-characters/19521/2 "2020-04-08T03:32:27Z")

</div>

[Docs.Oracle.com/en/java/javase/11/docs/api/java.base/java/lang/String.html#toCharArray()](http://Docs.Oracle.com/en/java/javase/11/docs/api/java.base/java/lang/String.html#toCharArray())

---

<div class="post-metadata">

**Author:** ![Math\_Machine](https://avatars.discourse-cdn.com/v4/letter/m/f14d63/32.png) [@Math\_Machine](https://discourse.processing.org/u/Math_Machine)\
**Post date:** [April 8, 2020, 3:43am UTC](https://discourse.processing.org/t/is-there-any-way-to-split-a-string-into-an-array-of-characters/19521/3 "2020-04-08T03:43:34Z")

</div>

thank you so much! Side note, why isn’t substring listed in the processing reference page?

---

<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:** [April 8, 2020, 3:51am UTC](https://discourse.processing.org/t/is-there-any-way-to-split-a-string-into-an-array-of-characters/19521/4 "2020-04-08T03:51:36Z")

</div>

[Processing.org/reference/String\_substring\_.html](http://Processing.org/reference/String_substring_.html)

---

<div class="post-metadata">

**Author:** ![Math\_Machine](https://avatars.discourse-cdn.com/v4/letter/m/f14d63/32.png) [@Math\_Machine](https://discourse.processing.org/u/Math_Machine)\
**Post date:** [April 8, 2020, 3:57am UTC](https://discourse.processing.org/t/is-there-any-way-to-split-a-string-into-an-array-of-characters/19521/5 "2020-04-08T03:57:21Z")

</div>

oh…well why can’t I find it here? [https://processing.org/reference/](https://processing.org/reference/)

---

<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:** [April 8, 2020, 4:00am UTC](https://discourse.processing.org/t/is-there-any-way-to-split-a-string-into-an-array-of-characters/19521/6 "2020-04-08T04:00:17Z")

</div>

It’s inside String’s reference: [Processing.org/reference/String.html](http://Processing.org/reference/String.html)

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [April 17, 2020, 7:45pm UTC](https://discourse.processing.org/t/is-there-any-way-to-split-a-string-into-an-array-of-characters/19521/7 "2020-04-17T19:45:20Z")

</div>

> [@Math\_Machine](#):
>
> why isn’t substring listed in the processing reference page?

> [@GoToLoop](#):
>
> It’s inside String’s reference

Note that this is true for String, and is also true for PImage, PGraphics, PFont, PShader, PVector, and everything under listed under **composite** on the reference – such as FloatList, HashMap, IntDict, JSONArray, Table, and more. All the classes – which are capitalized – have their methods listed under them, not on the main reference page.

---

<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:** [April 17, 2020, 9:07pm UTC](https://discourse.processing.org/t/is-there-any-way-to-split-a-string-into-an-array-of-characters/19521/8 "2020-04-17T21:07:36Z")

</div>

Yeah, well, I remember, I found this confusing when I began, because there is even a _String section_ on the reference page, but the really interesting part is **not** there, but on the String sub-page…

Also, PVector is not in the section data type, but math…

😉

---

<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:** [April 20, 2020, 5:31pm UTC](https://discourse.processing.org/t/is-there-any-way-to-split-a-string-into-an-array-of-characters/19521/9 "2020-04-20T17:31:38Z")

</div>

You had me at `"Hello?"`

> [@Math\_Machine](#):
>
> Is there any way that I can split up a string into an array of its individual components? Like, for example, if I had the string “hello?”, is there any way I could convert that into an array in the form {“h”,“e”,“l”,“l”,“o”,“?”

> **[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.

You can adapt this to store characters in an array:

```auto
  String s = "Hello?";
  for(int i = 0; i < s.length(); i++)
    {
    char c = s.charAt(i);
    println(c);

```

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/4/46b09cdc96aabfabf9da60db92af6b3fa3728c6b.png)  
`:) `
