Files
programming-lua/exercises/ch04/ex4_3.lua
2026-02-19 18:51:17 +02:00

19 lines
546 B
Lua

local function insert(str, i, o)
local first_half = str:sub(1, i - 1)
local latter_half = str:sub(i, -1)
return first_half .. o .. latter_half
end
local function tests()
local res = insert("hello world", 1, "start: ")
print(('insert("hello world", 1, "start: ") --> %s'):format(res))
res = insert("hello world", 7, "small ")
print(('insert("hello world", 7, "small ") --> %s'):format(res))
res = insert("hello world", 12, "!")
print(('insert("hello world", 12, "!") --> %s'):format(res))
end
tests()