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

Adding " " around text?

Started by KingofGamesYami, 22 April 2014 - 12:51 AM
KingofGamesYami #1
Posted 22 April 2014 - 02:51 AM
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 on 22 April 2014 - 01:34 AM
Bomb Bloke #2
Posted 22 April 2014 - 08:45 AM
If you ever do need to put quotes in strings, stick the good 'ol backslash escape character in front of them.

Eg:

print("\"text\"")
TheOddByte #3
Posted 23 April 2014 - 08:06 PM
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
Lyqyd #4
Posted 23 April 2014 - 08:27 PM

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.]]
TheOddByte #5
Posted 25 April 2014 - 05:30 PM

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
Lyqyd #6
Posted 25 April 2014 - 05:34 PM
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.