This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
MetalMiner's profile picture

[Lua] Remove line break

Started by MetalMiner, 21 September 2012 - 09:15 PM
MetalMiner #1
Posted 21 September 2012 - 11:15 PM
Hi

I have the following problem:
If I create a file like this:

Hello
World
then I read this file with

file = fs.open("filename")
content = file.readAll()

If I print the variable content, it prints this:

Hello
World

Is there any way to remove the line breaks, so it will print

HelloWorld
?

Thanks
MysticT #2
Posted 21 September 2012 - 11:33 PM
You can use string.gsub:

local s = file.readAll() -- file is the file handle
local result = string.gsub(s, "n", "") -- remove line breaks
print(result)
MetalMiner #3
Posted 21 September 2012 - 11:50 PM
So simple would this be…
Thank you :)/>/>