July 2018
Beginner
202 pages
5h 42m
English
Sometimes, you may have a large string (such as the contents of a file) and need to find out if it contains a smaller substring. This can be done with the string.substring function. This function takes two variables: the large string to search and a smaller string to look for. On success, it returns a number, which is the index at which the substring first appears. On failure, the function returns nil:
local sentence = "The quick brown fox"local word = "quick"local index = string.find(sentence, word)print ("substring found at index: " .. index)