0

I am new on Lua, the following is a string:

...
Test 1
abc 30
bcd 40
cde 50
...
Test 2
abc 30
bcd 40
cde 50
...

I wanna get the Int of each Test, how should I managed to achieve this? any suggestion will be appreciated!!!

3
  • Post your expected output Commented Aug 11, 2014 at 11:01
  • I expected the I can sort this string by each Test Commented Aug 11, 2014 at 12:53
  • The string is all the lines? Each line? Show what you have tried. Commented Aug 11, 2014 at 13:54

3 Answers 3

2

Adapt the code below to your needs. The input string is in s.

for k in s:gmatch("Test%s+(%d+)") do
   print(k)
end
Sign up to request clarification or add additional context in comments.

Comments

0

Generally,

a = "5"

can be converted into number using tonumber function.

val = tonumber("5") or val = tonumber(a)

gives 5 as a number from "5" which was string previously.

Comments

0

Extract numeric part with string.match and convert it with tonumber.

local str = "abc 321"
print(tonumber(str:match("%d+")))

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.