run time improvment

what takes more time for the Arduino to process:

this

if(text != "")
             text = "";

or this?

 text = "";

Which takes longer depends on whether the test succeeds, or not.

Far faster would be to quit f**king around with Strings, which you are obviously using, as that is NOT how to compare strings.

PaulS:
Which takes longer depends on whether the test succeeds, or not.

Far faster would be to quit f**king around with Strings, which you are obviously using, as that is NOT how to compare strings.

So will it be faster to compare the two strings with string::compare?

No, use character arrays.

Forget that String (capital S) exists on an Arduino. It might cause unexpected behaviour.

sterretje:
No, use character arrays.

Forget that String (capital S) exists on an Arduino. It might cause unexpected behaviour.

but it's not ideal for me because I don't know how many characters suppose to be on the string and arrays has constant size

You have to size the array for the largest possible string. The null terminator tells where the actual string ends.

Delta_G:
You have to size the array for the largest possible string. The null terminator tells where the actual string ends.

I think that the most ideal solution for this problem is using a dynamic memory allocated list.
But it’s not really necessary for my project.
Not only that, this solution consumes a lot of RAM memory.

What solution consumes more memory? The dynamic solution dos because you gotta store all the pointers.

Look, Arduino only runs one code at a time. So making your code consume less memory only in some situations doesn't actually save anything. You still can't write code that takes up so much memory that your longest message won't fit. So you might as well reserve room for it. That memory isn't useful elsewhere lest you crash when your string grows too large.