• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

Storing each line read with readStringUntil(‘\n’); incrementing , repeat next line

Q&A Forum › Category: ESP32 › Storing each line read with readStringUntil(‘\n’); incrementing , repeat next line
0 Vote Up Vote Down
William Lucid asked 3 years ago

Creating a text file of a list of words that will be inputted by reading file; using readStringUntil(‘\n’).
I can read a single line and store the first word.  How can the process be repeated for all lines.
How to save words as the file is read; to be used latter to compare word created in project?

Code snippet

Update 09/03/2022:

Code snippet updated with routine the reads filenames until end of file.  How tdo you read, for example the third word of the file?

William

Question Tags: ESP32, LittleFS, readStringUntil'\n')
5 Answers
0 Vote Up Vote Down
paulfjujo answered 3 years ago

hello,
 

i find very strange to use word to store (ascii) text reading …
but i work mainly with Microchip PIC … and don’t know all on arduino possibilities.

it is not a good way to do init , inside a loop for
make you init at the beginning of function or as global in your program

String inputTexte[10];

void readTexte()
{
if(LittleFS.exists("/Texte.txt"))
{
// Open a "Texte.txt" for reading
File word = LittleFS.open("Texte.txt", "r"); //input ascii
if (!word)
{
Serial.println("file 'Texte.txt' open failed or No 'Texte.txt' file");
}
else
{
while(Texte.available())
{
for(x=0 ; x < 10; x++) //Build an arrary of words
{
inputTexte[x] = Texte.readStringUntil('\n');
Serial.println(inputTexte[x]);
}
}
}
}
}

0 Vote Up Vote Down
William Lucid answered 3 years ago

Thank you paulfjujo.
Have list of word read from wordfile.txt.  Question now is how do I print third word in the list?
 
Appreciate your input!
William

0 Vote Up Vote Down
paulfjujo answered 3 years ago

hello,

did you get all values ?
what is the result of printout ?

can you post or show us your wordfile.txt
are each word delimited by LF in your file ?
usualy separator is ‘,’ or ‘;’ as in CSV file ..

Question now is how do I print third word in the list?

Serial.println(inputTexte[2]);
String table begin at index 0 , so third value is at index 2 ..

0 Vote Up Vote Down
William Lucid answered 3 years ago

Good Morning pauljujo,

List of words

Will give it a go…

 

William

0 Vote Up Vote Down
William Lucid answered 3 years ago

Having Pauljujo’s help; function for reading text file line by line is complete:

Gist of function code

Thank you Pauljujo!

William

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [New Edition] Build ESP32-CAM Projects eBook – 2nd Edition April 16, 2025
  • [eBook Updated] Learn ESP32 with Arduino IDE eBook – Version 3.2 April 16, 2025

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2025 · RandomNerdTutorials.com · All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.