Module:StringReplace

From Terra Invicta Official Wiki
Revision as of 18:51, 19 January 2026 by Redwah (talk | contribs) (Created page with "-- 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 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 .....")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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 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