Hello! I am attempting to make a function that loops through string
.split()
, but it does not look like the loop is picking up the result.
What do I want to achieve?
I am attempting to make a function that converts a string with commas into an array. Here is an example:
"Test 1,Test 2,Test 3"
{"Test 1", "Test 2", "Test 3"}
What is the issue?
The output of the function is always:
What solutions have I tried so far?
I have tried to look up solutions on the DevForum, but there are no answers that help!
The Code
Script
function CommaStringToArray(InputString)
print(InputString) -- This will print the InputString parameter correctly!
local ArrayResult = {}
for CurrentIndex, CurrentString in pairs(string.split(InputString, ",")) do
print(CurrentString[CurrentIndex]) --> nil
table.insert(ArrayResult, CurrentString[CurrentIndex])
end
return ArrayResult
end
print(CommaStringToArray("Test1,Test2,Test3")) --> nil
print(CommaStringToArray("Test")) --> nil
What is the issue here? Am I missing something?
Thanks,
TriumphantCreatorX