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

A list of characters, which can be saved into a file

Started by Luca_S, 08 February 2015 - 01:46 PM
Luca_S #1
Posted 08 February 2015 - 02:46 PM
Hello,

I have a little problem, I need all characters, which can be saved into a file and won't get lost, if i read the file again. I found this already:http://www.computercraft.info/forums2/index.php?/topic/536-box-drawing-characters/
but I dont want the viewable characters. I want the characters which can be saved and read from a File completely correctly, it's not important how you get them, characters got like this:

string.char(17)
are also useable for me. Hope someone can help me,

Luca
SquidDev #2
Posted 08 February 2015 - 02:52 PM
If you need to read all characters from a file then there is binary mode for reading files. For instance:


local file = fs.open("out", "wb")
local str = "HELLO WORLD"
for i = 0, #str do
  file.write(string.byte(str:sub(i, i)))
end
file.close

And:

local file = fs.open("out", "rb")
local str = {}
local char
repeat
  char = file.read()
  str[#str + 1] = char
until char == nil
str = table.concat(str)

This reads/writes each byte in turn instead. You could always hex/base64 encode it instead.
Edited on 08 February 2015 - 01:52 PM
Lignum #3
Posted 08 February 2015 - 03:14 PM
I'm not entirely sure but all of these are most definitely writable.
Luca_S #4
Posted 14 February 2015 - 09:41 AM
No, I dont need to read all characters on a file, but Lignums characters were enough, thanks :D/>
Bomb Bloke #5
Posted 14 February 2015 - 11:15 AM
Huh. Looks like some posts were pruned from this thread without explanation. Well that's insulting.
Lyqyd #6
Posted 14 February 2015 - 09:02 PM
Uh, negative. There are no moderator log entries for actions taken in this topic, so no posts have been removed.
Bomb Bloke #7
Posted 14 February 2015 - 10:03 PM
Nevertheless - they're gone!

Maybe it has something to do with the server move.