SD Card search specific text inside text file help

Hi i would like to ask for some assistance with my personal project.
Here is the scenario I want to read a line from the text file inside the SD card I manage read all the lines inside the text file but I cant search the exact text inside the text file.

Here is my expected output :

Initializing SD card...initialization done.
test.txt:
FIDenomStart
FIDenomEnd

and here is my code using carriage return and its output is :
Initializing SD card...initialization done.
test.txt:
FIDenomStart

#include <SPI.h>
#include <SD.h>
#include <EEPROM.h>



int FiDenomCount;

int FIDenomStart;
int FIDenomEnd;

File myFile;
int recNum = 0;

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

  Serial.print("Initializing SD card...");

  if (!SD.begin(53))
  {
    Serial.println("initialization failed!");
    while (1);
  }

  Serial.println("initialization done.");

  myFile = SD.open("test.txt");
  if (myFile)
  {
    Serial.println("test.txt:");
    while (myFile.available())
    {
      String list = myFile.readStringUntil('\r');
      recNum++;
 //     Serial.println(list + " " + recNum);


      if (list == "1stDenEnd")
      {
        FIDenomEnd = recNum;
        Serial.println("FIDenomEnd");
      }
      
      if (list == "1stDenStart")
      {
        FIDenomStart = recNum;
        Serial.println("FIDenomStart");
      }


    }
  }
}
void loop() {
  // nothing happens after setup
}

and here is my other code using line feed and its output :
Initializing SD card...initialization done.
test.txt:
FIDenomEnd

#include <SPI.h>
  #include <SD.h>
  #include <EEPROM.h>
  
  
  
  int FiDenomCount;
  
  int FIDenomStart;
  int FIDenomEnd;
  
  File myFile;
  int recNum = 0;
  
  void setup()
  {
    Serial.begin(9600);
    while (!Serial)
    {
    }
  
    Serial.print("Initializing SD card...");
  
    if (!SD.begin(53))
    {
      Serial.println("initialization failed!");
      while (1);
    }
  
    Serial.println("initialization done.");
  
    myFile = SD.open("test.txt");
    if (myFile)
    {
      Serial.println("test.txt:");
      while (myFile.available())
      {
        String list = myFile.readStringUntil('\n');
        recNum++;
  //      Serial.println(list + " " + recNum);
  
  
        if (list == "1stDenEnd")
        {
          FIDenomEnd = recNum;
          Serial.println("FIDenomEnd");
        }
        
        if (list == "1stDenStart")
        {
          FIDenomStart = recNum;
          Serial.println("FIDenomStart");
        }
  
  
      }
    }
  }
  void loop() {
    // nothing happens after setup
  }

You have a commented out serial print statement. Why is it commented out? A clue just might present itself, if you uncommented the line.

Of course, the print statement is rather useless, because you'll have a hard time determining exactly what is in line.

However, there is a trim() method of the String class that you might want to research (and use).

PaulS:
You have a commented out serial print statement. Why is it commented out? A clue just might present itself, if you uncommented the line.

Of course, the print statement is rather useless, because you'll have a hard time determining exactly what is in line.

However, there is a trim() method of the String class that you might want to research (and use).

Hi PaulS I commented out the serial print statement since i'm using the textfile in determining the location of the text that i've been searching so far I can search the text in the first line with readStringUntil('\r') but so far the others text are also unsearchable and I did manage to search the last text too using the readStringUntil('\n') but the same problem i encounter with the carriage return I can only search the last line and what I want to achieve is to search every single text content of the text file.

If your records are terminated by \r AND \n, which is quite usual, then readStringUntil('\n') is going to result in "someText\r" as the result. That will NOT match "someText".

Of course, the only way to determine what is ACTUALLY in line is to print it between markers:

Serial.print("line contains: [");
Serial.print(line);
Serial.println("]");

line contains: [someText]
is not the same as
line contains: [someText
]

The first result does not contain a \r. The second does.

String line = myFile.readStringUntil('\n').trim(); // Get rid of leading and trailing white space

will result in line NOT containing the \r that starts the end of record sequence.

PaulS:
If your records are terminated by \r AND \n, which is quite usual, then readStringUntil('\n') is going to result in "someText\r" as the result. That will NOT match "someText".

Of course, the only way to determine what is ACTUALLY in line is to print it between markers:

Serial.print("line contains: [");

Serial.print(line);
Serial.println("]");




line contains: [someText]
is not the same as 
line contains: [someText
]

The first result does not contain a \r. The second does.



String line = myFile.readStringUntil('\n').trim(); // Get rid of leading and trailing white space



will result in line NOT containing the \r that starts the end of record sequence.

Hi PaulS thanks for your reply I will try the code later if I have some free time.