Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

string.split貌似有点问题 #57

Open
ltccss opened this issue Jun 24, 2020 · 2 comments
Open

string.split貌似有点问题 #57

ltccss opened this issue Jun 24, 2020 · 2 comments

Comments

@ltccss
Copy link

ltccss commented Jun 24, 2020

if search_pos_begin < string.len(split_string) then

测试用例:string.split(“123|123|1”, “|”)
预期结果["123", "123", "1"]
实际结果["123", "123", ""]

@ltccss
Copy link
Author

ltccss commented Jun 24, 2020

另外注解里参数错了。。

@liaoyuzh
Copy link

liaoyuzh commented Feb 10, 2022

确实错了 提供一个亲测有效的:

local function split(input, sep)
	local t = {}
	local match_regex = "([^"..sep.."]+)"
	for str in string.gmatch(input, match_regex) do 
		table.insert(t, str)
	end
	return t
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants