回答編集履歴
1
test
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
```lua
|
2
2
|
function split(str, sep, idx)
|
3
|
-
|
3
|
+
local splitted = {}
|
4
4
|
local pre = 0
|
5
|
-
|
5
|
+
for i=1, #str do
|
6
|
-
|
6
|
+
if (string.sub(str, i, i) == sep) then
|
7
|
-
|
7
|
+
table.insert(splitted, string.sub(str, pre, i-1))
|
8
|
-
|
8
|
+
pre = i + 1
|
9
|
-
|
9
|
+
end
|
10
|
-
|
10
|
+
end
|
11
11
|
table.insert(splitted, string.sub(str, pre, #str))
|
12
|
-
|
12
|
+
return splitted[tonumber(idx)]
|
13
13
|
end
|
14
14
|
|
15
15
|
print(split("a-b-c", "-", "2"))
|