Jump to content




Question about Newlines


  • You cannot reply to this topic
5 replies to this topic

#1 ezfe

  • New Members
  • 1 posts

Posted 07 May 2013 - 05: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?

#2 sploders101

  • Members
  • 52 posts

Posted 07 May 2013 - 06: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.

#3 Hawk777

  • Members
  • 162 posts

Posted 07 May 2013 - 06: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.

#4 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 07 May 2013 - 08: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()

View PostHawk777, on 07 May 2013 - 06:32 PM, said:

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)

#5 PixelToast

  • Signature Abuser
  • 2,265 posts
  • Location3232235883

Posted 07 May 2013 - 10: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>"

View Posttheoriginalbit, on 07 May 2013 - 08:28 PM, said:

View PostHawk777, on 07 May 2013 - 06:32 PM, said:

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

#6 Hawk777

  • Members
  • 162 posts

Posted 10 May 2013 - 03:50 PM

View Posttheoriginalbit, on 07 May 2013 - 08:28 PM, said:

View PostHawk777, on 07 May 2013 - 06:32 PM, said:

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!





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users