# Splitting the String into multiple Arrays and Converting it to an int

**URL:** https://discourse.processing.org/t/splitting-the-string-into-multiple-arrays-and-converting-it-to-an-int/28502
**Category:** Electronics (Arduino, etc.)
**Tags:** homework
**Created:** [March 13, 2021, 2:29pm UTC](https://discourse.processing.org/t/splitting-the-string-into-multiple-arrays-and-converting-it-to-an-int/28502 "2021-03-13T14:29:06Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Nick2](https://avatars.discourse-cdn.com/v4/letter/n/3ec8ea/32.png) [@Nick2](https://discourse.processing.org/u/Nick2)
#### Post date: [March 13, 2021, 2:29pm UTC](https://discourse.processing.org/t/splitting-the-string-into-multiple-arrays-and-converting-it-to-an-int/28502/1 "2021-03-13T14:29:06Z")

</div>

Hi I am a bit new to processing and do not really know that much. I managed to display some serial data, but what I really need is a GUI to show the temperature from multiple ds18b20 sensors. but I need some help with Splitting the String into multiple Arrays and then converting those Arrays into a int.Could someone help me with this? Any help would be greatly appreciated.

Here is my code:

import processing.serial.\*;

Serial myPort;

String myString;

String s = myString;

int nl = 10;

int kleur = 127;

int cold = 20;

void setup()  
{  
size(500, 500);  
background(00);  
myPort = new Serial(this, “COM5”, 9600);

}

void draw() {  
while (myPort.available() \> 0) {  
background(0);  
String val = myPort.readStringUntil(nl);  
if (val != null) {  
rect(kleur, 200, 200, 200);  
textSize(17);  
fill(0, 102, 153, 204);  
text(val, 200, 200, 200);  
}  
}  
}

---

<div class="post-metadata">

### Author: ![micuat](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/micuat/32/19407_2.png) [@micuat](https://discourse.processing.org/u/micuat)
#### Post date: [March 13, 2021, 2:33pm UTC](https://discourse.processing.org/t/splitting-the-string-into-multiple-arrays-and-converting-it-to-an-int/28502/2 "2021-03-13T14:33:23Z")

</div>

Hi! Welcome to the forum. First, you can use `</>` button on the editor to format the code.

Working with serial input can be complicated. And it’s hard for us to debug because we don’t have the hardware you are working on. If you have an example data you get from the serial that would be helpful.

Without that information I think what you are looking for is literally `split`  
[https://processing.org/reference/split\_.html](https://processing.org/reference/split_.html)  
and the example shows you how to parse it as int 🙂

---

<div class="post-metadata">

### Author: ![Nick2](https://avatars.discourse-cdn.com/v4/letter/n/3ec8ea/32.png) [@Nick2](https://discourse.processing.org/u/Nick2)
#### Post date: [March 13, 2021, 2:46pm UTC](https://discourse.processing.org/t/splitting-the-string-into-multiple-arrays-and-converting-it-to-an-int/28502/3 "2021-03-13T14:46:50Z")

</div>

Hi, first of all thank you for replying!  
But whenever I use that method it shows:java.lang.reflect.InvocationTargetException

---

<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: [March 14, 2021, 6:07am UTC](https://discourse.processing.org/t/splitting-the-string-into-multiple-arrays-and-converting-it-to-an-int/28502/4 "2021-03-14T06:07:39Z")

</div>

Please show example data

And show how you used split()
