6v6gt:
If you want to use the Arduino version of the String class...
Wow. No thanks.
There is no better way to shoot yourself in the foot than by using String. Not only that, you'll wonder where the shot came from. It comes at random times. Sometimes, it manifests as a different injury. Fun.
benskylinegodzilla:
split the header at the first \n and discard everything else
I could answer this specific question with code like this:
char header[MAX_HEADER_SIZE];
void something()
{
// Find a specific char in the header array
char *newlinePtr = strchr( header, '\n' );
if (newlinePtr != nullptr) {
// It's pointing at the newline char
*newlinePtr = '\0'; // terminate the string here
// Later characters are still in the array, but
// this C string (NOT the String class) has been
// terminated at the first newline char.
// Other C string functions will stop here,
// ignoring the remaining contents.
}
However, this is probably the wrong question.
In this environment, it is very unlikely that you can save an entire "thing" and then process it all at once. Because there is limited RAM, you will almost certainly have to process "things" as they are received, gradually accumulating only a few key pieces of information. BONUS: this approach is also faster.
So I have to ask:
-
What is in the header that you really want?
-
Do you have some code that is reading this stream of bytes?