←  Ask a Pro

ComputerCraft | Programmable Computers for Minecraft

»

Adding " " around text?

KingofGamesYami's Photo KingofGamesYami 22 Apr 2014

So, I was originally going to use textutils.serialize(string.sub(format)) to do this, but I doubt that would work now since it would return 'string.sub("format")' I think. Is there any other way of doing this or is it impossible? I'm working on creating a file format based on html & BBC.

Edit: nvm, I'm a moron... It's going to return a string anyway (Duh)
Edited by KingofGamesYami, 22 April 2014 - 02:34 AM.
Quote

Bomb Bloke's Photo Bomb Bloke 22 Apr 2014

If you ever do need to put quotes in strings, stick the good 'ol backslash escape character in front of them.

Eg:

print("\"text\"")
Quote

TheOddByte's Photo TheOddByte 23 Apr 2014

 Bomb Bloke, on 22 April 2014 - 07:45 AM, said:

If you ever do need to put quotes in strings, stick the good 'ol backslash escape character in front of them.

Eg:

print("\"text\"")
And if I'm correct this would also work
print( '"Hello World!"' )
As you may have noticed I started wrapping the text with a single quotation mark then used a double since that's what's going to be printed, You can ofcourse do the opposite way around :3
Quote

Lyqyd's Photo Lyqyd 23 Apr 2014

local str = [[Of course,
"block quotes" don't care about what's
inside them and are probably the easiest
way to create complex string literals.]]
Quote

TheOddByte's Photo TheOddByte 25 Apr 2014

 Lyqyd, on 23 April 2014 - 07:27 PM, said:

local str = [[Of course,
"block quotes" don't care about what's
inside them and are probably the easiest
way to create complex string literals.]]
You can also do this right?
print[[
Blah blah, this is some text
this is a new line
etc.
]]
So that you don't have to assign it to a variable
Quote

Lyqyd's Photo Lyqyd 25 Apr 2014

Sure, you can use them like any other string literal without issue, as far as I know. You might want to include a space after the print, but it should work fine.
Quote