function hybrid(string1,string2)
if string1 and string2 then
local SplitCharacters = {}
string2 = string2 .. " "
for i = 1,#string1 do
table.insert(SplitCharacters,#SplitCharacters+1,string.sub(string1,i,i)) -- Insert every single character of the string into a table
end
local StartReplacing = #string1-#string2
StartReplacing += 1
for i, SCh in pairs(SplitCharacters) do
if i > StartReplacing then
SplitCharacters[i] = string.sub(string2,i-StartReplacing,i-StartReplacing) -- Replace the characters
end
end
local FinalString = ""
for _, Ch in pairs(SplitCharacters) do
FinalString = FinalString .. Ch
end
return FinalString
end
end
print(hybrid("Good morning!","afternoon"))
I may be wrong, just tell me if this is what you want
Shorter? Sure. Better? Well. This post Be careful when using assert() and Why explains that it is better not to use assert() because of bad script performance. Mine script may be 50 lines longer but 50x less script memory consuming.
function hybrid(string1, string2)
if typeof(string1) ~= "string" or typeof(string2) ~= "string" then
return warn("string expected")
end
return string.sub(string1, 1, #string2 / 2)..string2
end