Replace a single character in a Char Array with 3 Characters for URL Encoding


The only way to change the length of a “string” is to copy it to another “string” of the correct length. This is what “String” was doing for you and each time used more free memory that you did not see it using.


Good boy, getting rid of that pesky String! Try to look at this approach:

char testString[] = "Hello: World * Universe!";
char buffer[50];
byte sourceIndex = 0, targetIndex = 0;
while (testString[sourceIndex] != 0)
  char cc = testString[sourceIndex++];
  if (cc == ' ') buffer[targetIndex++] = '+';
  else if (cc == '*')
    buffer[targetIndex++] = '%';
    buffer[targetIndex++] = '2';
    buffer[targetIndex++] = 'A';
  else buffer[targetIndex++] = cc;
buffer[targetIndex] = 0;

Code is untested, but it should be pretty straight forward to understand the method! :slight_smile:


to use any string function (i.e. strcmp()) your string must be null terminated (the array must have '\0' at the end)


Data incomming for serial is 6 char: "SFFFFF"

Is it SFFFFF\lf\cr\0

or is it


Check your line endings. Where is the serial data coming from?

can you post your full code?