8

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?

AakashM
  • 62,551
  • 17
  • 151
  • 186
Theun Arbeider
  • 5,259
  • 11
  • 45
  • 68

2 Answers2

16

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+"
)
lunixbochs
  • 21,757
  • 2
  • 39
  • 47
  • 4
    If you use string.match instead of string.find you won't need to discard the first two results. Parents around ´%d+´ are not needed in any case. You might have to call `tonumber` in the result: `number = tonumber(string.match(theString, "%d+"))` – kikito Feb 28 '12 at 08:27
5

string.match (stringvar, "%d+")

snogglethorpe
  • 1,751
  • 15
  • 16