-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring.lua
More file actions
49 lines (38 loc) · 1.16 KB
/
string.lua
File metadata and controls
49 lines (38 loc) · 1.16 KB
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
39
40
41
42
43
44
45
46
47
48
49
function string.ToTable( input )
local tbl = {}
local str = tostring( input )
for i = 1, #str do
tbl[i] = string.sub( str, i, i )
end
return tbl
end
function string.Explode( separator, str )
if ( separator == "" ) then return string.ToTable( str ) end
local ret = {}
local current_pos = 1
for i = 1, string.len( str ) do
local start_pos, end_pos = string.find( str, separator, current_pos, true )
if ( not start_pos ) then break end
ret[ i ] = string.sub( str, current_pos, start_pos - 1 )
current_pos = end_pos + 1
end
ret[ #ret + 1 ] = string.sub( str, current_pos )
return ret
end
function string.Split( str, delimiter )
return string.Explode( delimiter, str )
end
function string.Implode( seperator, tbl ) return
table.concat( tbl, seperator )
end
function string.Replace( str, tofind, toreplace )
local tbl = string.Explode( tofind, str )
if ( tbl[ 1 ] ) then return table.concat( tbl, toreplace ) end
return str
end
function string.StartsWith( str, start )
return string.sub( str, 1, string.len( start ) ) == start
end
function string.EndsWith( str, endStr )
return endStr == "" or string.sub( str, -string.len( endStr ) ) == endStr
end