Replace String Characters by Index in Lua -
If you have been hanged in every way, then you can easily understand what I am trying to do . I want to replace characters with other characters on some characters. This is what I am currently doing:
word = getwordoflength (10) found = string.rep ("_", 10) while found ~ words = four getcharfromuser () temp = "" If I = 1, for 10 words: sub (i, i) == four then temp = temp..char else temp = temp..found: sub (i, i) found end end = temp end < / Code> Now, I find it impossible to be stupid and inefficient, but there is probably no better way. Bottom line, what's the 'right' way to do this?
where found ~ local word for local word = getcharfromuser (): gmatch ('()' .. char) found = found: sub (1, i-1) .. char..found: sub (i + 1) end end
Another way:
got it ~ ~ word word local char = getcharfromuser () in the word: gmatch ('()' ..c) found = found: gsub ('( ). ', {[I] = four}) End of End
Comments
Post a Comment