Jump to content

String.gsub Help

1 reply to this topic

#1 johnnic

  • Members
  • 50 posts
  • LocationSomewhere in ****** County, *******

Posted 03 October 2013 - 09:33 PM

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?

#2 AgentE382

  • Members
  • 119 posts

Posted 03 October 2013 - 10:23 PM

Change this:

while stringthing:gsub(m,replcdby[p]) do

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.

1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users