For example,
local a = "Hello and good day to you!"
local b = "Hi there and good day to you too!"
(some form of detection)
Line 5 from string a = "to"
Line 2 from string b = "there"
I would love someone to answer how to detect the specific words!
You can use string.gmatch
to iterate over the words in the string.
local function GetWord(str, n) local count = 0 for word in str:gmatch("%w+") do count = count + 1 if count == n then return word end end end
%w+
will capture runs of alphanumeric characters, which are the "words" being counted. GetWord
returns the n
th "word" in str
.
This is very simple, just use string.find()
:
local string = "Hello World!" local s_find = string.find(string, "Hello")
The found part of the string can be used for whatever is needed with the string.