|
| 16 Jun 2015 10:26 PM |
Let's say my string is "one two three"
I wanna somehow get the text between string.find(s,"one") and strnig.find(s,"three")
HOWEVER
Let's say my string is "three one two three"
I want it to still get the text between the first find ("one") and the second find ("three") but the second find is after the first find
My script that doesn't work due to the HOWEVER part is:
local i,j = string.find(s,"one") local i2,j2 = string.find(s,"three") print(string.sub(s,i,j2-1) |
|
|
| Report Abuse |
|
|
|
| 16 Jun 2015 10:29 PM |
| # operator then string.sub |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 16 Jun 2015 10:29 PM |
string.match is really useful for this:
local val = string.match(s, "one (.-) three"); |
|
|
| Report Abuse |
|
|
|
| 16 Jun 2015 10:30 PM |
cnt you saved my life again i hate string manipulation |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 16 Jun 2015 10:31 PM |
Well it's pretty simple in this case:
'one (.-) three' First it'll fine a one that is followed by a space, then followed by a series of characters followed by a space, then followed by a three. The parenthesis around .- (which gets characters non-greedily) make it so you get it returned, captured. |
|
|
| Report Abuse |
|
|
TimeTicks
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
|
| 16 Jun 2015 10:32 PM |
| @teamkilled I hate the scrubs on your autoduels. |
|
|
| Report Abuse |
|
|