-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhstring.lua
68 lines (50 loc) · 1.24 KB
/
hstring.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
local hstring = {
__VERSION = '1.0',
__DESCRIPTION = 'String-related functions for lua',
}
function hstring.test()
print("hstring merge")
end
function hstring.replace(s, oldValue, newValue)
return string.gsub(s, oldValue, newValue);
end;
function hstring.splitBy(str, delimiter)
local arr = {}
local i = 1;
local regex = '([^'..delimiter..']+)';
for word in string.gmatch(str, regex) do
--print(word)
arr[i]= word;
i = i+1;
end
-- print(arr)
return arr
end
function hstring.arrToString(arr)
n = #(arr)
for i=1,n do
print(arr[i])
end
end
function hstring.textUntil(input, text)
local position = string.find(input,text)
local response = string.sub(input,0,position -1 )
return response
end
function hstring.randomChars()
local randlowercase = string.char(math.random(97, 97 + 25))
local count = 0;
local response = ''
while count < 7 do
response = response .. randlowercase;
randlowercase = string.char(math.random(97, 97 + 25))
count = count + 1;
end
return response;
end
-- print(hstring.randomChars())
-- local array = splitBy('cat,dog', ',')
-- arrToString(array)
-- local array1 = splitBy('8:40', ':')
-- arrToString(array1)
return hstring