Error: request for member 'indexOf' in 'a', which is of non-class type 'char'

Hi, everyone! I just making a Arduino<->C# app but I can't figure out how can I escape from this error:

void setup() {Serial.begin(9600);}

void loop() {
if(Serial.available())
  {
    char a = Serial.read();

     if(a.indexOf("Hour:") > 0) { // err: request for member 'indexOf' in 'a', which is of non-class type 'char'
        String lastHour = a.substring(6); // err: request for member 'substring' in 'a', which is of non-class type 'char'
        int hour = lastHour.toInt();
      }
  }
}

The program makes 2 errors: First one is in the if(a.index ... section. The error says "request for member 'indexOf' in 'a', which is of non-class type 'char'" but I can't figure out how can I solve this error. Same for String lastHour ...

Can anyone help :grinning:? Thanks.

char a = Serial.read();

This reads a single char from Serial

Consider using Serial.readString() instead to read a String into a variable

That's really worked after I turned the code into String a = Serial.readString();. You are the best, thanks!

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