# Termination of a String

**URL:** https://discourse.processing.org/t/termination-of-a-string/44431
**Category:** Processing
**Created:** [May 14, 2024, 1:23pm UTC](https://discourse.processing.org/t/termination-of-a-string/44431 "2024-05-14T13:23:22Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![leclerke](https://avatars.discourse-cdn.com/v4/letter/l/f9ae1b/32.png) [@leclerke](https://discourse.processing.org/u/leclerke)
#### Post date: [May 14, 2024, 1:23pm UTC](https://discourse.processing.org/t/termination-of-a-string/44431/1 "2024-05-14T13:23:22Z")

</div>

Hello,  
I am stuck transforming a char-array to a String.  
When using:  
`byte[] inBuffer = new byte[60];`  
`myPort.readBytesUntil(lf, inBuffer);`  
`tring myString = new String(inBuffer);`  
there seems to be some data after the “lf” in the string. How do I remove this? The length of the byte is variable, so 60 byte is maximum. How can I make shure to convert only the bytes until “lf” (from the readUntil). I think I have to add a tremination byte to the array or something.  
I hope you understand what I mean.

---

<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: [May 14, 2024, 1:32pm UTC](https://discourse.processing.org/t/termination-of-a-string/44431/2 "2024-05-14T13:32:30Z")

</div>

> **[bufferUntil() / Libraries](https://processing.org/reference/libraries/serial/serial_bufferuntil_)**
>
> Sets a specific byte to buffer until before calling serialEvent().

---

<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: [May 14, 2024, 2:04pm UTC](https://discourse.processing.org/t/termination-of-a-string/44431/3 "2024-05-14T14:04:04Z")

</div>

Hell @leclerke,

Assuming you are using this:

> **[Serial.println() - Arduino Reference](https://www.arduino.cc/reference/en/language/functions/communication/serial/println/)**
>
> The Arduino programming language Reference, organized into Functions, Variable and Constant, and Structure keywords.

A simple example of the data that you are sending will help.

> [@leclerke](#):
>
> there seems to be some data after the “lf” in the string.

I would expect the array to be initialized filled with zeroes.

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/c/e/ce9fac65bb083a3adff0ec7347aed9194854e776.png)

In the context of the code example you provided this may work:

```auto
byte [] inBuffer = {'T', 'e', 's', 't', '\r','\n','0','0','0','0','0'};

String s = new String(inBuffer);
println(s); // This will also print the \r\n from above!

int i = s.indexOf("\r");
println(s.substring(0, i));

```

A bit or research will reveal that there are other ways to do this.

`:)`
