xreceive - Receives available data from Serial, stores into global String buffer. Note if the global String buffer is 1024 bytes or more, it will be emptied. xprocess - Uses the provided String parameter and checks if it exists within the main buffer, if so, removes that part of text.
I tried using Serial.readString() directly, however with doing serialbuffer.concat(Serial.readString()), neither .indexOf, neither .replace worked...
Using this code, .indexOf works, however .replace doesn't.
Can you show a small working sketch that shows the problem and that we can try ? thank you very much
I think that you have to write easy and simple code. Don't try to put a multitude of functionality into a single line.
Others might see other problems, but this code line got my attention at first glance, because it is over-complicated :
Looking at it better, I think that is a bug. You have reserved one byte in memory for the contents of 'serialbuffertemp', and then you write the received text to it.
This is a worse error than just a size. It is more important that this is not a text buffer, but a pointer to a literal. A literal is not meant to be modified, so the compiler may not allocate memory for it, but place a pointer to any other string with the same content.
For example, these two strings will actually share the same place in memory:
char* a = "ABCDE";
char* b = "CDE";
Since the line char* serialbuffertemp = ""; points to the string terminator char, which is in any other string in the program, than most likely the compiler will not allocate even 1 character for this line.
Bugs are never where you think they are (as pointed out by @Koepel )
Your topic has been moved to a more suitable location on the forum. Installation and Troubleshooting is not for problems with (nor for advice on) your project See About the Installation & Troubleshooting category.
I agree, however I couldn't find any proper methods to remove a word from a c-string.
Let me clarify, the plan is like this:
Get data from serial
Check if a word trigger exists in the buffer, if so, remove it from the buffer and continue to the requested function.
I have tried using String only, however as I mentioned in my original post, neither .replace() nor .indexOf() work when doing serialbuffer.concat(Serial.readString())
However both functions do work if I just do serialbuffer = Serial.readString()
Agreed, I made a mash up of those and it kind of worked but the whole code was so complicated and messy I just couldn't handle using it in my project, plus there were too many concerns about the stability.