# A simple data split , what am I doing wrong?

**URL:** <https://discourse.processing.org/t/a-simple-data-split-what-am-i-doing-wrong/28551>\
**Category:** Electronics (Arduino, etc.)\
**Created:** [March 15, 2021, 8:09pm UTC](https://discourse.processing.org/t/a-simple-data-split-what-am-i-doing-wrong/28551 "2021-03-15T20:09:33Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![laptophead](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/laptophead/32/2701_2.png) [@laptophead](https://discourse.processing.org/u/laptophead)\
**Post date:** [March 15, 2021, 8:09pm UTC](https://discourse.processing.org/t/a-simple-data-split-what-am-i-doing-wrong/28551/1 "2021-03-15T20:09:33Z")

</div>

I am receiving a 2 value string from an arduino delimited by a space.

```auto
if(serialConnect)
{
  if (myPort.available() > 0) {
    IncomingSTR = myPort.readStringUntil(lf);
    //println (IncomingStr);
    if (IncomingSTR != null) {
      println (IncomingSTR);

      String [] list = split(IncomingSTR, ' ');
      if ( list.length >=2 )
      {
        int Mach_ID= int (list [0]);
        int LastUptime= int(list [1]);

println (Mach_ID+ " and " +LastUptime);
println (list [0]);
println (list [1]);

        //println ( Dev);
       // SaveToFile ();
      }
    }
  } // end of if port available

```

the int LastUptime always comes as a zero.  
While the println (list [1]); is returning the correct integer from ardu.

So simple, I fee stupid, where is the mistake?  
Thanks

---

<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 15, 2021, 8:14pm UTC](https://discourse.processing.org/t/a-simple-data-split-what-am-i-doing-wrong/28551/2 "2021-03-15T20:14:54Z")

</div>

> [@laptophead](#):
>
> ` int LastUptime= int(list [1]);`

```auto
        int LastUptime= int(trim(list [1]));

```

---

<div class="post-metadata">

**Author:** ![laptophead](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/laptophead/32/2701_2.png) [@laptophead](https://discourse.processing.org/u/laptophead)\
**Post date:** [March 15, 2021, 8:19pm UTC](https://discourse.processing.org/t/a-simple-data-split-what-am-i-doing-wrong/28551/3 "2021-03-15T20:19:18Z")

</div>

Christof

Danke,

That worked. The processing documentation does not mention the trim under the Split reference.  
How would someone know?

they go:

| Name | ### split() |
| --- | --- |
| Examples | String men = “Chernenko,Andropov,Brezhnev”; String[] list = split(men, ‘,’); // list[0] is now “Chernenko”, list[1] is “Andropov”… |

Maybe they should update the user guide…

Thanks again  
mitch

---

<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 15, 2021, 8:28pm UTC](https://discourse.processing.org/t/a-simple-data-split-what-am-i-doing-wrong/28551/4 "2021-03-15T20:28:27Z")

</div>

Haha, good point! 😉

---

<div class="post-metadata">

**Author:** ![jb4x](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jb4x/32/789_2.png) [@jb4x](https://discourse.processing.org/u/jb4x)\
**Post date:** [March 15, 2021, 9:02pm UTC](https://discourse.processing.org/t/a-simple-data-split-what-am-i-doing-wrong/28551/5 "2021-03-15T21:02:48Z")

</div>

You should not have to use the split function there.

I think you have a whitespace character at the end of your string that is not a “space”. So when you split with the space character, the first value is correct but the second one is “value + whitespace”. And because of that you can’t convert it to an int and you first need to use the `trim()` function to get rid of that whitespace.

So no need to update the documentation here.
