回答編集履歴

1

2022/12/29 03:05

投稿

melian
melian

スコア19618

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