Read name from SD using Id

please help me with a problem in mySD card in a file i have information of employee with their id like


So here the employe enters his id using a keypad like A1, his name must be printed on LCD acessing the id , like search the text file for name wth this id and display on LCD, can u please help with this…

Thank you in advance.

Take a look at 'Stream.find()' AKA 'File.find()'.
It will find the next occurrence of a search string, starting at the file pointer's current position.
When (if) the search string is found, it returns 'true' and the file pointer is left at the first char after the search string. 'position()' returns the current file pointer position, and 'seek()' can be used to move it as required.

can youu please explain or suggest me an example how to use those functions


Did you try looking in the Arduino reference?

I wrote this to test these functions, and as a reminder for the future when I need to do similar.
It searches a file for the string “onto” and changes it to “ONTO”:-

// Libraries:-
#include <SPI.h>
#include <SD.h>

// Constants:-
const byte csPin = 4;

File myFile;

void setup()
    Serial.print(F("Initialising SD card....."));
    if (!SD.begin(csPin))
        Serial.println(F("Initialisation failed!"));
        while (true);                               // Initialisation failed - stop here.
    Serial.println(F("Initialisation done."));

    myFile ="SDFile1.txt"), FILE_WRITE); // Open for reading and writing. (File pointer
    if (myFile)                                     // starts at END of file.)
        Serial.println(F("File opened OK.\n"));;                             // Move file pointer to beginning of file.
        char searchString[]="onto";                 // The search string to look for.
        if(myFile.find(searchString))               // Search for string.
            Serial.print("\"");                     // String found - notify user.
            Serial.print(searchString);             //    "     "       "      "
            Serial.print("\"");                     //    "     "       "      "
            Serial.println(F(" was found"));        //    "     "       "      "
            int pointerPos=myFile.position();    // File pointer is at next char after search string.
            Serial.print(F("File pointer now at position: ")); // Print it's current position.
            Serial.println(pointerPos);              //   "    "      "       "

            // Now change "onto" to "ONTO":-
            int len=strlen(searchString);           // Get the length of the search string.
            pointerPos -= len;                   // Move file pointer back to start of search string.
  ;             //  "    "      "      "  "    "   "    "      "
            Serial.print(F("Now at position: "));   // Print the new file pointer position.
            Serial.println(pointerPos);              //   "    "   "   "      "       "
                myFile.write("ONTO");               // Change the string to the opposite case.
            Serial.println(F("searchString was NOT found!"));
        myFile.close();                                 // Close the file.
        Serial.println(F("Error opening file!"));

void loop(){}

thank u

i just have a small little query if i find the string and i used it once, now when i want to find other string does the search begin from where the pointer ended previously or frpm the strting of the file

'find()' starts it's search from the current file pointer position.

That's why, in my example, I did this before the search:-;                             // Move file pointer to beginning of file.

Because in that case I wanted to search from the beginning of the file, but the file pointer was at the end of the file, as noted in the comments.

(With a little experimentation, you could have easily discovered this. It's the best way to learn. :slight_smile: )