#include <Arduino.h>
//String_class_h
//using namespace std;
struct d
{
String S; // Strings - Complete parsed Strings
String P; // Parsed - Exta storage just in case
int I; // Index - Stores the index location of the delimiter
int L; // Length -
};
struct d p[10] = {};
bool ReadingSerial = false;
void ReadSerial() {
String uI;
int length;
int pos;
//CHECK IF SERIAL IS AVAILABLE
if(Serial.available() > 0) {
uI = Serial.readStringUntil('\n');
ReadingSerial = false;
}
//FIND THE LENGTH(NUMBER OF CHARACTERS)
length = uI.length();
printf("Input length = %i\n", length);
//Add a terminating character to the end of the string
uI[length] = '\n';
printf("User Input = %s\n", uI.c_str());
//Finding a character or Substring
p[1].I = uI.indexOf(" ");
printf("Index of first delimiter: %i\n", p[1].I);
strncpy(&p[1].S[0], &uI[0], 3);
printf("SubString = %s\n", p[1].S.c_str());
Serial.println(p[1].S);
//String sub = uI.substring(d + 1);
//printf("SubString = %s\n", sub.c_str());
}
void setup() {
Serial.setTimeout(2000);
Serial.begin(115200);
Serial.println("Hello, ESP32-S3!");
}
void loop() {
if(Serial.available() > 0) {
ReadingSerial = true;
ReadSerial();
}
delay(10); // this speeds up the simulation
}
Loading
esp32-s3-devkitc-1
esp32-s3-devkitc-1