# Can I Sort my incoming String based on the first char?

**URL:** <https://discourse.processing.org/t/can-i-sort-my-incoming-string-based-on-the-first-char/15847>\
**Category:** Electronics (Arduino, etc.)\
**Created:** [November 26, 2019, 9:55pm UTC](https://discourse.processing.org/t/can-i-sort-my-incoming-string-based-on-the-first-char/15847 "2019-11-26T21:55:22Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [November 27, 2019, 2:41am UTC](https://discourse.processing.org/t/can-i-sort-my-incoming-string-based-on-the-first-char/15847/4 "2019-11-27T02:41:08Z")

</div>

thanks for posting the split code,  
but in that form we only can guess what might go wrong.

but for test, to get something run-able, must put in some more minutes and make a MVCE  
i show you what i tried and the results.

( as close as possible to your code  
but without having that many variables / you not posted the declaration )

```auto
String inBuffer;

inBuffer = "158018 70222 149288 44793 12944 94 -96.0 -305.8 129.4 221.9 45.2 1 -1 0 0 0";
//inBuffer = "e 96.0 305.8 129.4 221.9";

char c1 = inBuffer.charAt(0);

if (c1 == 'e') {
  float[] errs = float(split(inBuffer, ' '));
  println(errs);
} else {
  float[] nums = float(split(inBuffer, ' '));
  println(nums);
}

/*

[0] 158018.0
[1] 70222.0
[2] 149288.0
[3] 44793.0
[4] 12944.0
[5] 94.0
[6] -96.0
[7] -305.8
[8] 129.4
[9] 221.9
[10] 45.2
[11] 1.0
[12] -1.0
[13] 0.0
[14] 0.0
[15] 0.0
*/

/*
[0] NaN
[1] 96.0
[2] 305.8
[3] 129.4
[4] 221.9
*/

```

in other words, with the provided 2 lines your problem could not be reproduced here.

* * *

to the serial code, is might help to use also the  
[https://processing.org/reference/trim\_.html](https://processing.org/reference/trim_.html)  
on the “inBuffer” to clean it.

* * *

also about the inBuffer eval,  
do use data only if you sure they exist! as i posted  
[Trouble with the Serial port read](https://discourse.processing.org/t/trouble-with-the-serial-port-read/10724/4) here

---

_[View the full topic](https://discourse.processing.org/t/can-i-sort-my-incoming-string-based-on-the-first-char/15847)._
