Arduino File.find()

Description

The File.find() function reads data from the file until the target is found. The function returns true if target is found, false if timed out (see File.setTimeout()).

The File.find() function inherits from the Stream utility class.

Syntax

file.find(target)

file.find(target, length)

Parameter Values

  • file: an instance of a class that inherits from File.
  • target: the string to search for. Allowed data types: char.
  • length: length of the target. Allowed data types: size_t.

Return Values

  • true: if target is found.
  • false: if timed out.

Example Code

Create a arduino.txt file with the below content

myInt=-52 myFloat=-12.70 myString=Arduino
/* * Created by ArduinoGetStarted.com * * This example code is in the public domain * * Tutorial page: https://arduinogetstarted.com/reference/library/arduino-file.find */ #include <SD.h> #define PIN_SPI_CS 4 File file; void setup() { Serial.begin(9600); if (!SD.begin(PIN_SPI_CS)) { Serial.println(F("SD CARD FAILED, OR NOT PRESENT!")); while (1); // don't do anything more: } file = SD.open("arduino.txt", FILE_READ); if (file) { if (file.find("myFloat")) Serial.println("myFloat is FOUND"); else Serial.println("myFloat is NOT FOUND"); if (file.find("myDouble")) Serial.println("myDouble is FOUND"); else Serial.println("myDouble is NOT FOUND"); file.close(); } else { Serial.print(F("SD Card: error on opening file")); } } void loop() { }
  • Open Serial Monitor, you will see as below:
COM6
Send
myFloat is FOUND myDouble is NOT FOUND
Autoscroll Show timestamp
Clear output
9600 baud  
Newline  

ARDUINO BUY RECOMMENDATION

Arduino UNO R3
Arduino Starter Kit
Please note: These are Amazon affiliate links. If you buy the components through these links, We will get a commission at no extra cost to you. We appreciate it.

※ OUR MESSAGES