Read ine breaks from txt file

Hello everyone.

I´m trying to read from the local folder an txt file.

If i put on it a breakline, Corona simply trims there the string.

If i dont break the line and try put \n Corona reads it as normal text.

I record the txt as utf-8.

how to read or put a break line on the txt file?

Is correct the system.ResourceDirectory, and the txt file will be packed in the apk?

Thanks.

This is the code:

[lua]local function leficheiro(txt)
local contents = “”
local path = system.pathForFile( txt, system.ResourceDirectory )
local file = io.open( path, “r” )
if (file) then
– read all contents of file into a string
contents = file:read()
file:close()

– io.close( file )
print(contents)

else
print(“file not found”)
end
print(path)
return contents
end[/lua]

Ciao!

Mi sono imbattuto recentemente in un problema simile. Ho dovuto usare le stringhe  utf-8 dal server remoto.

Per leggere queste stringhe ed evitare problemi ho dovuto usare il plugin " utf8".

È gratuito ma ricorda di inserire la chiamata nella tua build.

Trova la documentazione qui:  https://docs.coronalabs.com/plugin/utf8/index.html .

For the second part I think it’s okay but for a better answer I should know what the data is for…

Anyway, take a look here and I’m sure you’ll be clearer:

https://docs.coronalabs.com/guide/data/readWriteFiles/index.html#system-directories

Spero che questo ti aiuta

Hello maximo97.

I think the plugin is working (it dont need download), but i see no diference.

The text still not apears wirth the breakline but apears the “\n”, also if the text as a paragraf it is cutted the string.

Dont need specific function from that pluggin to read the text?

I think i will put evering inside the *.lua file…

Thanks.

Hi!

I did a test and it seems to work. I could have misunderstood.

Can you attach a sample file with the one you would like to get?

Are you asking for something like this:

https://forums.coronalabs.com/topic/49613-split-string-to-separate-strings/ ?

máximo97, if read a text without breaklines or \n it apears on screen, let say unformated. If i wish to make a paragraph break, on the text file the corona does not read all the text, cut the string (all text in a string) on the place where we put a break line.

Thanks for your time.

Forgive me, I do not understand…

I did a simple test:

and what I get is this:

Hello \n Corona C:\Users\Rita\Desktop\test\myFile.txt Hello \n Corona 1C:\Users\Rita\Desktop\test\myFile.utf-8

no white line…

Ciao!

Mi sono imbattuto recentemente in un problema simile. Ho dovuto usare le stringhe  utf-8 dal server remoto.

Per leggere queste stringhe ed evitare problemi ho dovuto usare il plugin " utf8".

È gratuito ma ricorda di inserire la chiamata nella tua build.

Trova la documentazione qui:  https://docs.coronalabs.com/plugin/utf8/index.html .

For the second part I think it’s okay but for a better answer I should know what the data is for…

Anyway, take a look here and I’m sure you’ll be clearer:

https://docs.coronalabs.com/guide/data/readWriteFiles/index.html#system-directories

Spero che questo ti aiuta

Hello maximo97.

I think the plugin is working (it dont need download), but i see no diference.

The text still not apears wirth the breakline but apears the “\n”, also if the text as a paragraf it is cutted the string.

Dont need specific function from that pluggin to read the text?

I think i will put evering inside the *.lua file…

Thanks.

Hi!

I did a test and it seems to work. I could have misunderstood.

Can you attach a sample file with the one you would like to get?

Are you asking for something like this:

https://forums.coronalabs.com/topic/49613-split-string-to-separate-strings/ ?

máximo97, if read a text without breaklines or \n it apears on screen, let say unformated. If i wish to make a paragraph break, on the text file the corona does not read all the text, cut the string (all text in a string) on the place where we put a break line.

Thanks for your time.

Forgive me, I do not understand…

I did a simple test:

and what I get is this:

Hello \n Corona C:\Users\Rita\Desktop\test\myFile.txt Hello \n Corona 1C:\Users\Rita\Desktop\test\myFile.utf-8

no white line…