Is there a way to convert a string or char to int

I have tried everything I can think of but cannot get the compiler to accept converting char to int. I tried first reading byte buffer but couldn’t find a way to convert that. So, I tried read a single character in at a time and adding it to a string because then I thought I could iterate the string and pull the data that I need. The clock that I am using accepts int for each position of hour and minute (num1,num2,num3,num4). So I am sending a request to a server which replys with “04,51,40” + crlf. I need to take the 0 and put in num1, 4 in num2, 5 in num3, 1 in num4. Any help would be appreciated.

void GetTimeReply ()
  String sTemp;
  byte buffer[80];
  int len = client.available();
  if (len > 0)
    char c =;
    sTemp += c;
    while (client.available() > 0)
      char c =;
      sTemp += c;
  char c1 = sTemp.substring(1);
  num1 = int(c1);
//  num1 = int(sTemp.substring(1));
//  Serial.print(num1);
//  num2 = int(sTemp.substring(2));
//  Serial.print(num2);
//  num3 = int(sTemp.substring(4));
//  Serial.print(num3);
//  num4 = int(sTemp.substring(5));
//  Serial.print(num4);

  // Set Clock time
  // SetClockDisplayFromServer(num1,num2,num3,num4)
  Serial.println("  GetTimeReply - Exit");
  bGetTimeReplyDone = true;

Not that you should be using "S"trings on an Arduino anyway, but I think you're looking for stoi().

Thanks, I was to optimistic!

I think you’re looking for toInt
(Never heard of stoi)

If you are using Strings, then the below type operation should work.

  if (readString.length() >0) {
    int n = readString.toInt();

So, I guess the first comment about not using string functions must be true.
I have

    //0123456789012345678 <---Chars in string position
    //2020,02,01,09,28,58     <---Return string from server
    // This code below
    String sYear;
    sYear = sTemp.substring(0, 4);
    String sMonth;
    sMonth = sTemp.substring(5, 2);
    String sDay;
    sDay = sTemp.substring(8, 2);
    String sHour;
    sHour = sTemp.substring(11, 2);
    String sMinute;
    sMinute = sTemp.substring(14, 2);
    String sSeconds;
    sSeconds = sTemp.substring(17, 2);

09:35:44.674 → -->
09:35:44.674 → 2020,02,01,09,35,44
09:35:44.674 → <–Length=21
09:35:44.709 → Year=2020
09:35:44.709 → Month=20,
09:35:44.709 → Day=20,02,
09:35:44.709 → Hour=20,02,01,
09:35:44.709 → Minute=20,02,01,09,
09:35:44.709 → Seconds=20,02,01,09,35,
09:35:45.685 → GetTimeReply - Exit

Has anyone been able to get the string functions to work? Is there a different library?

XY Problem. it looks like you have something like a webclient.

What hardware are you using? What do you want to achieve?

in the end I guess you want something like strtok and atoi

if you really always get "04,51,40" + crlf. and really want to have it in single digits than even a simple char array buffer will work num1=buffer[0]-32; num2=buffer[1]-32; num3=buffer[3]-32; etc could work.

I have an Arduino Mega with ethernet shield connected to 4 digit 7 segment display with rtc module. I press button on Arduino and it makes a websocket to server sending "Time" request. Server responds with datetime string in the following format "2020,02,01,09,28,58"+crlf. I then was trying to parse through the string but was not realizing that the substring function on Arduino does (from, to) as opposed to (from, length). So, I got everything functioning except simple things I am stumbling over. Current road block is I want to "Serial.println(" before and after setting time...BUT Compiler gives me error "no matching function for call to 'DateTime::toString()". I also tried making DateTime dtNow variable, assigning to it and then trying "Serial.println(dtNow.toString())" but I think the compiler doesn't accept the toString method.

"Has anyone been able to get the string functions to work?"

The String functions usually work for me.