Pharsing SD CARD text file

Hello Every one

I have an D1 mini wemos ESP8266 Device connected to a Micro Sd card reading adapter. On the SD card
these a text file named wifi.txt that has a string with wifi username and password separated by a comma

I.E MYUSERNAME , MYPASSWORD

How can I read the file and save the two strings as separate strings in my application? So the username = MYUSERNAME password =MYPASSWORD using the comma separator as a string splitter.

void Load_SD_Card(){
// re-open the file for reading:
myFile = SD.open("TEST.TXT");
if (myFile) {
Serial.println("TEST.TXT");

// read from the file until there's nothing else in it:
while (myFile.available()) {
char data= myFile.read();

//Would like to add parsing code here to get the two separate strings for username and password.
I tried for loops of the char but not successful.

Serial.write(data);

}
///Serial.write(myFile.read());

// close the file:
myFile.close();

} else {
// if the file didn't open, print an error:
Serial.println("error opening test.txt");
}
}I

What would be the best way to do this, please?

Thank you.

I prefer char aByte= myFile.read(); which more accurately describes what is happening instead of
char data= myFile.read(); .

Anyway, parse after everything is read from the file not while you are reading from the text file.

After myFile.close();

Hello

Thank you for the reply. Serial.write(myFile.read()); read out the text file data but I would like to convert
this into a string variable to parse for the two comma separated strings.

converting myFile.read() to a usable string then parsing could be the solution.

Hope you can help

Cheers.

After all of the bytes are in the char array, you would need to use C string functions to split the array into two.

I suggest reading up on this --->