To whoever takes pity on me by reading this post…
I’m not a programmer by trade, so having spent the last several hours trying to digest “Programming in Lua”, I’m significantly humbled enough to cry uncle and ask for help!
So… what I want to do is pretty simple. Take words in a string and replace them with other words. Fill in the blanks, as it were.
I can make it work, but it’s ugly. I know a do while or for loop will do the trick… just can’t seem to get they syntax right. Any help is most appreciated!!
Here’s what I have (side question: how does everyone else get their code pasted in so neatly and formatted?)
–Test to replace words in a string
local currentStory = “I want to insert noun one here and noun two here and noun three here”
print("Original story is this: " … currentStory)
local noun = {}
noun[1] = “club”
noun[2] = “cat”
noun[3] = “computer”
currentStory = string.gsub (currentStory, “noun”, noun[1], 1)
print("+++++")
print(currentStory)
currentStory = string.gsub (currentStory, “noun”, noun[2], 1)
print("+++++")
print(currentStory)
currentStory = string.gsub (currentStory, “noun”, noun[3], 1)
print("+++++")
print(currentStory)
–[[ tried to get this to work as a loop with no luck using the following code
for i = 1, 3 do
local x = 1
currentStory = string.gsub ( currentStory, “noun”, noun[x], 1)
print("Next the story is this: " … currentStory)
x = x + 1
end --]]
–Final text should read “I want to insert club one here and cat two here and computer three here”
Thanks so much!
Chris [import]uid: 97836 topic_id: 24970 reply_id: 324970[/import]