# \[SOLVED\] uint8\_t buffer to String

**URL:** <https://forum.arduino.cc/t/solved-uint8_t-buffer-to-string/329938>\
**Category:** Programming\
**Created:** [August 16, 2015, 6:25pm UTC](https://forum.arduino.cc/t/solved-uint8_t-buffer-to-string/329938 "2015-08-16T18:25:09Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dexterous](https://avatars.discourse-cdn.com/v4/letter/d/bb73d2/32.png) [@Dexterous](https://forum.arduino.cc/u/Dexterous)\
**Post date:** [August 16, 2015, 6:25pm UTC](https://forum.arduino.cc/t/solved-uint8_t-buffer-to-string/329938/1 "2015-08-16T18:25:09Z")

</div>

May Peace and Blessings be upon you!

I've been looking around for some reference to convert my whole buffer of uint8\_t to use as a String.  
The reason was the String class offers us much easy to use and diverse methods or functions to process the data.  
This thing usually comes across to us when we are using some library and the library processes and gives you some data into a char\* or uint8\_t type of buffer. After getting the data in the buffer new comers usually don't know how to handle and process it.  
I had a similar scenario, but when I try to use google and this forum I didn't find much reliable solution to do it, and then I figured out some other way to achieve it using type casting.

Here is my solution:

if you have some kind of data buffer of uint8\_t e.g:

```cpp
uint8_t buff[700] = {0};

```

and you want to convert all the buffer to the String. Then just call this code below and you will have your buffer as a String object.

```cpp
String str = (char*)buff;

```

and now you can use this String object to use any of its methods e.g:

```cpp
char L = str.length();

```

OR

```cpp
String new_str = str.substring(8, 15);

```

easy han?

Warning: Strings takes some more memory on your Arduino than uint8\_t, So, be sure that what you are going to do otherwise your Arduino might keep on resetting again and again if the memory bloats.

I hope it will help you.

Regards,  
Dexterous.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [August 17, 2015, 10:25am UTC](https://forum.arduino.cc/t/solved-uint8_t-buffer-to-string/329938/2 "2015-08-17T10:25:39Z")

</div>

> I hope it will help you.

Learning to not use Strings would be even more helpful.

---

<div class="post-metadata">

**Author:** ![gjntn](https://avatars.discourse-cdn.com/v4/letter/g/73ab20/32.png) [@gjntn](https://forum.arduino.cc/u/gjntn)\
**Post date:** [November 26, 2015, 4:55pm UTC](https://forum.arduino.cc/t/solved-uint8_t-buffer-to-string/329938/3 "2015-11-26T16:55:28Z")

</div>

Hi! 🙂

> Learning to not use Strings would be even more helpful.

Learning to really help others, would be even more useful to everyone. Bring up some richer arguments, with sources, recommendations or whatever supports your comments around forums.

Everyone at programming world knows that handling integers is better, the lower memory elements the better, maybe, but just maybe, that's why...

> Warning: Strings takes some more memory on your Arduino than uint8\_t, So, be sure that what you are going to do otherwise your Arduino might keep on resetting again and again if the memory bloats.

So, for the record. This recipe posted by @Dexterous comes very in handy when working with HTTP responses when working with C at another microcontroller solution, but well, I suppose that even with that case of use, the String class doesn't seem to have any sense of existing... 😛

Dexterous, thanks for this straightforward recipe and for your blessings!

Good vibes to all!

Jon.

---

<div class="post-metadata">

**Author:** ![acoolfrood](https://avatars.discourse-cdn.com/v4/letter/a/e495f1/32.png) [@acoolfrood](https://forum.arduino.cc/u/acoolfrood)\
**Post date:** [May 15, 2016, 10:28am UTC](https://forum.arduino.cc/t/solved-uint8_t-buffer-to-string/329938/4 "2016-05-15T10:28:46Z")

</div>

Most useful post I found in days of trawling the net! Thanks for this, I can now convert uin8\_t to strings which has been causing me trouble for days 🙂

---

<div class="post-metadata">

**Author:** ![dev\_1](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/dev_1/32/215847_2.png) [@dev\_1](https://forum.arduino.cc/u/dev_1)\
**Post date:** [May 15, 2016, 3:01pm UTC](https://forum.arduino.cc/t/solved-uint8_t-buffer-to-string/329938/5 "2016-05-15T15:01:45Z")

</div>

Hmm... self-SOLVED pseudo-questions and praise from newbies? Be warned. **Don't use String™**. Using the `String` class will cause you trouble forever.

Maybe the OP should read [this recent discussion](http://forum.arduino.cc/index.php?topic=385867.msg2661171#msg2661171), [this summary](http://forum.arduino.cc/index.php?topic=382944.msg2640860#msg2640860) of the issues from all over the innertubes, and [this cautionary tale](http://forum.arduino.cc/index.php?topic=382705.msg2638322#msg2638322). If you still wonder if `String` is useful, read [this](http://forum.arduino.cc/index.php?topic=396099.msg2726746#msg2726746).

OP, if you want "to really help others", ask a useful question or provide a useful answer. Don't claim to solve the _wrong problem_ for your 3rd post. If you have a 700-byte array and you convert it to a `String`, that allocates another 700 bytes. Using 1400 bytes for an HTTP response to extract one `uint8_t` is no solution -- it's unbelievably **wasteful**. The HTTP response should have been parsed as it was received.

And if you don't understand how to do that, ASK a question that may help others.

---

<div class="post-metadata">

**Author:** ![acoolfrood](https://avatars.discourse-cdn.com/v4/letter/a/e495f1/32.png) [@acoolfrood](https://forum.arduino.cc/u/acoolfrood)\
**Post date:** [May 15, 2016, 7:57pm UTC](https://forum.arduino.cc/t/solved-uint8_t-buffer-to-string/329938/6 "2016-05-15T19:57:42Z")

</div>

Good to know. It's fair to say that after posting the praise above I fell at the next hurdle in my code. Learning this stuff is difficult and there seems to be multiple ways to do each thing. I was trying to convert to a string as I needed to reference individual characters in the uinit8\_t. It seemed that charAt could only parse strings from the references I read. I later tried it on the uinit8\_t and it worked! The string reference pages could use a big "do not use" header, as when beginig to learn I'm sure most people will follow these reference instructions before trawling forums and asking questions.

---

<div class="post-metadata">

**Author:** ![dev\_1](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/dev_1/32/215847_2.png) [@dev\_1](https://forum.arduino.cc/u/dev_1)\
**Post date:** [May 15, 2016, 8:10pm UTC](https://forum.arduino.cc/t/solved-uint8_t-buffer-to-string/329938/7 "2016-05-15T20:10:59Z")

</div>

> The string reference pages could use a big "do not use" header

Now THAT's a useful post!

Since it wasn't clear, I edited my post to address it to the OP. But thanks for adding your experience. That's so much more convincing than "don't do that."

Cheers,  
/dev

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [May 5, 2021, 9:26pm UTC](https://forum.arduino.cc/t/solved-uint8_t-buffer-to-string/329938/8 "2021-05-05T21:26:17Z")

</div>

Closed on May 5, 2021, 9:26pm UTC


