Jump to content




Adding " " around text?


5 replies to this topic

#1 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 22 April 2014 - 01: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 by KingofGamesYami, 22 April 2014 - 02:34 AM.


#2 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 22 April 2014 - 07: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\"")


#3 TheOddByte

    Lazy Coder

  • Members
  • 1,607 posts
  • LocationSweden

Posted 23 April 2014 - 07:06 PM

 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

#4 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 23 April 2014 - 07: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.]]


#5 TheOddByte

    Lazy Coder

  • Members
  • 1,607 posts
  • LocationSweden

Posted 25 April 2014 - 04:30 PM

 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

#6 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 25 April 2014 - 04: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.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users