Jump to content

Taking letters from a string


tommymaster

Recommended Posts

Posted

Hi!
After a few minutes of research i finall found a way to take out letters from a string.
This is an example:

local text = "test3"
print (text:gsub('test', ''))

It outputs " "3"    1" but i only need number 3 after the word. How may i take out the number 1 after 3 and convert "3" to number?

Posted

it does return just 3, print just outputs both arguments it returns.

local text = "test3test3"

local num, count = text:gsub('test', '')

print(num)
--> 33

print(count)
--> 2

 

  • Thanks 1
Posted (edited)

and if for example if i have a string as variable like this: "1x5" how can i take out the "1x", and the opposite, how could i take out "x5"?

Edited by tommymaster

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...