Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding a number in a string lua

A simple question.

When a roll has been done it shows as:

"Need Roll - 150 for [SomeItem] by [SomePerson] + role bonus"

I wish for some way to isolate the number 150. However there is no such thing as a split in lua (as far as I know) so what's the best way to accomplish this?

like image 310
Theun Arbeider Avatar asked Feb 27 '12 22:02

Theun Arbeider


1 Answers

If this is for WoW, check out this strsplit function there.

Otherwise, you can do it with string.find or string.match and patterns. It could be as simple as doing a string.match for %d+ to find the first number in the string, as follows:

number = string.match(
    "Need Roll - 150 for [SomeItem] by [SomePerson] + role bonus",
    "%d+"
)
like image 83
lunixbochs Avatar answered Sep 28 '22 02:09

lunixbochs