EyeonTips:Script/Reference/Libraries/string

From VFXPedia

Jump to: navigation, search

General String Tips

  • Strings are joined using two dots:
name = first_name .. " " .. family_name
  • Inside quoted strings, the backslash character will escape special characters. For example, a new-line is written as \n, a tab stop as \t and the double quotation sign as \". This means that you have to write double backslashes to actually produce a backslash character, which is mostly used if you write hard-coded path names. Compare:
-- invalid, would treat \n as a new-line character!
mypath = "x:\projects\new"
-- correct
mypath = "x:\\projects\\new"
  • There is no distinction between single and double quoation marks in LUA when it comes to the treatment of the backslash character. The only advantage of using single quotes is the ability to write unescaped quotation marks. Things like \n will still be treated as special characters.
-- still invalid!
mypath = 'x:\projects\new'
  • Regular expressions (as used in string.find, string.match or string.gsub) add another escape character: the percentage sign ( % ) is used to mark special commands and thus needs to be escaped by another percentage sign if its literal meaning is desired. Many more characters have a special meaning in regular expressions, so refer to the patterns tutorial for more info.
string.find(s, "%%\\") -- looks for % followed by a backslash 
  • To pad a number with leading zeros (e.g. the frame number part of a file name), use string.format:
-- will produce something like output.00042.jpg
filename = "output." .. string.format("%05d", frame) .. ".jpg"