I have a string, I just want to read the last characters after the last ";".
Example: "12/5/2015; 00: 00: 05; 90" -> Read only the "90"
I have a string, I just want to read the last characters after the last ";".
Example: "12/5/2015; 00: 00: 05; 90" -> Read only the "90"
Read 2 last characters:
str = "12/5/2015;00:00:05;90"
print(string.sub(s, -2))
Break into 3:
str = '12/5/2015;00:00:05;90'
for word in string.gmatch(str, '([^;]+)') do
print(word)
end
Placing each part in an Array:
a = {} -- array 1
b = {} -- array 2
c = {} -- array 3
str = '12/5/2015;00:00:05;90'
op = 0
for word in string.gmatch(str, '([^;]+)') do
op = op+1
if op == 1 then
a[1] = word
elseif op == 2 then
b[1] = word
elseif op == 3 then
c[1] = word
end
end
print(a[1])
print(b[1])
print(c[1])
You can run the code and test online here
Try this:
s = "12/5/2015;00:00:05;90"
print(s:match(".*;(.+)$"))
.*;
advances to the last ;
.
(.+)$
captures and returns the remainder to the end of the string.