String.gsub Help
johnnic 03 Oct 2013
Hello there. I am trying to find same words in strings that are commonly mistyped/misspelled, and then replace them with the autocorrect term. The autocorrect list is in the form "bad:good", and i know it is correctly reading them since I had it iterate through them.
Word List: http://pastebin.com/fP2kpJNp
Actual Code: http://pastebin.com/wym3xaPH
There is no error, but string.gsub is not replacing the words. Any help?
Word List: http://pastebin.com/fP2kpJNp
Actual Code: http://pastebin.com/wym3xaPH
There is no error, but string.gsub is not replacing the words. Any help?
AgentE382 03 Oct 2013
Change this:
Into this:
string.gsub returns the changed copy of the string. It doesn't modify the string in-place. If you want that, simply assign the return value of string.gsub back to the same string. Also, delete the while loop. string.gsub replaces all of the occurrences of the pattern with one function call.
while stringthing:gsub(m,replcdby[p]) do print("FOUND") end
Into this:
stringthing = stringthing:gsub(m,replcdby[p])
string.gsub returns the changed copy of the string. It doesn't modify the string in-place. If you want that, simply assign the return value of string.gsub back to the same string. Also, delete the while loop. string.gsub replaces all of the occurrences of the pattern with one function call.