Watchmaker Wiki

The ultimate watch maker for Android Wear!

User Tools

Site Tools


tips:quotesinstrings

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
tips:quotesinstrings [2015/02/06 16:15] – [Apostrophes, Quotes, and Braces (Oh, my!)] jt3tips:quotesinstrings [2015/02/06 16:19] (current) – [Apostrophes, Quotes, and Braces (Oh, my!)] jt3
Line 9: Line 9:
 ===== Apostrophes, Quotes, and Braces (Oh, my!) ===== ===== Apostrophes, Quotes, and Braces (Oh, my!) =====
  
-Dealing with strings is usually pretty straightforward.  However, in LUA formulas, you're often mixing these strings with mathematical or string manipulation functions that require the use of some sort of string identifier.  Most people use apostrophes (single-quotes) or quotation marks (double-quotes) for this.  LUA doesn't usually care **which** identifier you use, but your string happens to use the same character as your identifier, LUA can get confused.+Dealing with strings is usually pretty straightforward.  However, in LUA formulas, you're often mixing these strings with mathematical or string manipulation functions that require the use of some sort of string identifier.  Most people use apostrophes (single-quotes) or quotation marks (double-quotes) for this.  LUA doesn't usually care **which** identifier you use, but if your string happens to use the same character as your identifier, LUA can get confused.
  
 Okay, what does that mean?  Basically, it means that if your string has apostrophes, then you can't use apostrophes as identifiers.  Take the following: Okay, what does that mean?  Basically, it means that if your string has apostrophes, then you can't use apostrophes as identifiers.  Take the following:
  
    string.len('This way to John's house')    string.len('This way to John's house')
-    + 
-everything is great until you hit that apostrophe in the word "John's" Suddenly, the string function thinks that it's reached the end of the string, and all hell breaks loose.  Okay, not really, but the formula will certainly fail.+Everything is great until you hit that apostrophe in the word "John's" Suddenly, the string function thinks that it's reached the end of the string, and all hell breaks loose.  Okay, not really, but the formula will certainly fail.
  
 So how do we prevent this?  Easy.  Just don't use the same identifier.  If your string has apostrophes, use quotes as the identifier.  If it has quotes, use apostophes as the identifier.  But what if it's a variable, and you don't know what it will have, such as with a calendar text item?  No problem.  In that case, just use double brackets, like this: So how do we prevent this?  Easy.  Just don't use the same identifier.  If your string has apostrophes, use quotes as the identifier.  If it has quotes, use apostophes as the identifier.  But what if it's a variable, and you don't know what it will have, such as with a calendar text item?  No problem.  In that case, just use double brackets, like this:
Line 21: Line 21:
    string.sub([[{c1t}]],1,15)    string.sub([[{c1t}]],1,15)
  
 +This way, your text item can have quotes OR apostrophies, and it will still be fine.  It can't have double-brackets, but if you're in the habit of doing that in your calendar items... well... stop it!
tips/quotesinstrings.1423239346.txt.gz · Last modified: 2015/02/06 16:15 by jt3