Yes, no. You can split something by the nth character with string.sub().Shadowblitz16 wrote:is there a function that splits the string between the nth char?
and supports negative values?
You can make a simple function that supports negative values.
Code: Select all
function splitTheNthChar(str, i)
if i > 0 then
return string.sub(str,1,i)
elseif i < 0 then
return string.reverse(string.sub(string.reverse(str),1,-i))
end
end
In other words:
Code: Select all
str = "12,3,68"
print(splitTheNthChar(str, 2))--prints "12"
print(splitTheNthChar(str, -2))--prints "68"