1 posts
Posted 07 May 2013 - 06:17 PM
Title: Question about Newlines
I am making a system to write the contents of a website to a monitor, and want to be able to handle newline directly from the text. (using \n would be preferable). How can I go about this?
52 posts
Posted 07 May 2013 - 07:15 PM
I would help you if I could but I've tried the same thing and had no such luck. I await any answers.
161 posts
Posted 07 May 2013 - 07:32 PM
I’m not sure what problem you’re having, but you can certainly get an HTTP response and see newlines in it. If you do an HTTP get and then call readAll() on the returned handle, you get a single string which contains newlines in the form of character number 10.
7508 posts
Location
Australia
Posted 07 May 2013 - 09:28 PM
Ok so to do newlines you use \n
However term.write and monObj.write (where monObj is your wrapped peripheral) have no built in support for the newline characters and will print a ? in its place. this is where the
print and
write functions come into play as they have support for it. Now by default the
print and
write functions point to the main terminal so we first need to redirect it to the monitor like so
-- get our monitor
local monitor = peripheral.wrap('left')
-- redirect the term api to the monitor
term.redirect(monitor)
-- print out our stuff
print("THIS\nIS\nCOMPUTERCRAFT!")
write("Hello ComputerCraft.")
-- restore the term api back to the main terminal
term.restore()
I’m not sure what problem you’re having, but you can certainly get an HTTP response and see newlines in it. If you do an HTTP get and then call readAll() on the returned handle, you get a single string which contains newlines in the form of character number 10.
What the……….. how does this………… i dont even…………. it doesn't answer OP question, it would just print ? in place of all the newlines… (
btw the newline byte is 10)
2217 posts
Location
3232235883
Posted 07 May 2013 - 11:23 PM
if you mean convert <br> to newlines (how its rendered in a browser) do this
str = string.gsub(str,"<br>","\n")
if you want to replace bytecodes with newline just use:
string.char(code)
in replace of "<br>"
I’m not sure what problem you’re having, but you can certainly get an HTTP response and see newlines in it. If you do an HTTP get and then call readAll() on the returned handle, you get a single string which contains newlines in the form of character number 10.
What the……….. how does this………… i dont even…………. it doesn't answer OP question, it would just print ? in place of all the newlines… (
btw the newline byte is 10)
yes it does -_-/> the OP clearly asked how to read the website, and how would it print ? for the newlines, string.byte("\n") return 10
161 posts
Posted 10 May 2013 - 04:50 PM
I’m not sure what problem you’re having, but you can certainly get an HTTP response and see newlines in it. If you do an HTTP get and then call readAll() on the returned handle, you get a single string which contains newlines in the form of character number 10.
What the……….. how does this………… i dont even…………. it doesn't answer OP question, it would just print ? in place of all the newlines… (
btw the newline byte is 10)
That would be because I didn’t understand the question properly then. I thought the question was about how to find the newlines in an HTTP response, not about how to move the cursor on the screen!