Invalid conversion from 'const char*' to 'char' for simple delimiter

Hey guys,

can someone tell me why I get this error message?

Code:

String split(String s, char parser, int index) {
  String rs="";
  int parserIndex = index;
  int parserCnt=0;
  int rFromIndex=0, rToIndex=-1;
  while (index >= parserCnt) {
    rFromIndex = rToIndex+1;
    rToIndex = s.indexOf(parser,rFromIndex);
    if (index == parserCnt) {
      if (rToIndex == 0 || rToIndex == -1) return "";
      return s.substring(rFromIndex,rToIndex);
    } else parserCnt++;
  }
  return rs;
}

void setup() {
  // put your setup code here, to run once:
  String myStr = "/my/new/string";
  char delimiter = "/";
  String myStrPrt = split(myStr, delimiter, 1);
}

void loop() {
  // put your main code here, to run repeatedly:

}

Error message:

C:\Users\alve89\AppData\Local\Temp\arduino_modified_sketch_966093\sketch_apr16a.ino: In function 'void setup()': sketch_apr16a:20:20: error: invalid conversion from 'const char*' to 'char' [-fpermissive] 20 | char delimiter = "/"; // doesn't work with an "a" neither

I thought it might be issued by the slash because it's not a char but it still doesn't work with an a.

Thanks in advance!

A char variable, by definition, can only hold a single character whilst "/" is actually 2 characters, one for the slash and another for the terminating zero of the string.
Use char delimiter = '/'; instead

I just wanted to update / close this post because I remembered that - but thank you for your quick reply! Issue solved.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.