FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
algorithm/lua_string_to_table.lua at master · guyuyun/algorithm · GitHub
guyuyun
algorithm
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
algorithm
/
lua_string_to_table.lua
Copy path
More file actions
More file actions
Latest commit
History
History
History
13 lines (10 loc) · 397 Bytes
Breadcrumbs
algorithm
/
lua_string_to_table.lua
Copy path
File metadata and controls
13 lines (10 loc) · 397 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
--
在LUA中,没有类似python的str.split()函数,如果要将一个字符串按照指定的符号分割,并存到table中。
--
如将a="1,2,3"转换为{1,2,3}
a
=
"
1,2,3,4,
"
--
或者 a="1,2,3,4" 不论最后一个是否有","
t
=
{}
for
w
in
string.gmatch
(
a
,
"
([^',']+)
"
)
do
--
按照“,”分割字符串
table.insert
(
t
,
w
)
end
for
k
,
v
in
ipairs
(
t
)
do
print
(
k
..
"
:
"
..
v
)
end
Back
|
FazBrowse Home
|
New Git URL