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!
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 nth "word" in str.
orrrrrrrrrrr string.find()
I think you interpreted the question entirely differently, your answer is not an alternative to mine.
1wafflel, thanks!
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.
But I'm on about locating specific parts of the string, not specific words.
Let me rephrase, I'm on about a function to locate specific words based on lines of the string such as "string.find(string, 2) won't fine "World! will it?
This discussion is preserved as it was. New answers, comments, and votes are closed.
1 comment
string.find()