Module:StringReplace
From Terra Invicta Official Wiki
Documentation for this module may be created at Module:StringReplace/doc
-- This is a helper module for replacing text in strings
local p = {}
local sfind = string.find
local ssub = string.sub
-- Replaces ONE instance of the stringToReplace with replacementString in the fullString
function p.replace(fullString, stringToReplace, replacementString)
local si, ei = sfind(fullString, stringToReplace, 1, true)
if not si then
return fullString
end
local prefix = ssub(fullString,1,si - 1)
local suffix = ssub(fullString,ei+1)
return prefix .. replacementString .. suffix
end
return p


