Finding a number in a lua string

Simple question.

When the roll has been completed, it is displayed as:

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

I want to somehow highlight the number 150. However, there is no such thing as a split in lua (as far as I know), and what is the best way to do this?

+4
source share
2 answers

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

Otherwise, you can do this using string.find or string.match and templates . It can be as simple as making string.match for %d+ to find the first number in a string, as shown below:

 number = string.match( "Need Roll - 150 for [SomeItem] by [SomePerson] + role bonus", "%d+" ) 
+8
source

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

+3
source

Source: https://habr.com/ru/post/1398708/


All Articles