Azzera filtri
Azzera filtri

Read/write text file in an app

1 visualizzazione (ultimi 30 giorni)
Peter de Goot
Peter de Goot il 22 Giu 2020
Commentato: Peter de Goot il 23 Giu 2020
I have something quite simple that seems somehow very difficult to do! I would like to print a text file, then later read it, from an app. The text is just ascii text, not data, tables, numbers or arrays or anything like that. The text comes from and will be sent back to app.textarea.value. I want to make notes in this text area, save them, then recall them. The notes may have paragraphs and so on. I just want to save it as text, and read it back in as text. What is the simplest way to do this?

Risposte (1)

Jiahao CHANG
Jiahao CHANG il 23 Giu 2020
Hi Peter,
I think you can use the function fopen and fprintf to create and write to text file.
Then, you can try to use fgets or fgetl to read line from file.
Use some loop so that you can read full line for your text file.
  1 Commento
Peter de Goot
Peter de Goot il 23 Giu 2020
Yes well, I have been trying for a couple of hours. It seems not a natural thing to do. The text area is stored as a character string, or as a vector of character strings. A new line in the text area creates a new line characters in a second row of the vector. If you just read/write character by character, the paragraphs are lost. So it is is not so straightforward, I have not found any examples of how to do this.

Accedi per commentare.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by