forked from ReikaKalseki/DragonIndustries
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstrings.lua
38 lines (35 loc) · 827 Bytes
/
strings.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
function lastIndexOf(str, seek)
local flip = string.reverse(str)
local s,e = string.find(str, seek, 1, true)
--log(flip .. " > " .. (s and s or "nil"))
if s and e then
s = string.len(str)-s
e = string.len(str)-e
return s,e
end
end
function splitAfter(str, mark)
local s,e = lastIndexOf(str, mark)
if s and e then
local part = string.sub(str, e+1)
--log(part)
return tonumber(part)
end
end
function splitString(str, seek)
local ret = {}
for s in str:gmatch("([^" .. seek .. "]+)") do
table.insert(ret, s)
end
return ret
end
function literalReplace(str, seek, repl)
if seek == repl then return str end
local idx,idx2 = str:find(seek, 1, true)
local ret = str
while idx and idx2 do
ret = ret:sub(1,idx-1) .. repl .. ret:sub(idx2+1, #ret)
idx,idx2 = ret:find(seek, 1, true)
end
return ret
end