|
| 22 Oct 2014 07:42 AM |
I'm trying to call the output of string.find, but since it outputs two different numbers (The beginning of the string and the end of the string) I can't figure out how to call the separate numbers.
I am using the output in string.sub |
|
|
| Report Abuse |
|
|
|
| 22 Oct 2014 07:45 AM |
....?
I don't understand what you mean "call the output of"
Unless you mean:
local S = "Hello" local Start,End = S:find("ello"); print(S:sub(Start,End)); |
|
|
| Report Abuse |
|
|
|
| 22 Oct 2014 07:50 AM |
stringPositions = string.find(string, targetWord) msg = string.sub(string, 1, *Start of found word* - 1) |
|
|
| Report Abuse |
|
|
|
| 22 Oct 2014 07:52 AM |
I just told you how.....
Use two variables. |
|
|
| Report Abuse |
|
|
ohno1112
|
  |
| Joined: 23 Mar 2013 |
| Total Posts: 833 |
|
|
| 22 Oct 2014 07:53 AM |
string = "this is a string"
print(string.find(string,"string")) outputs 11 16
basically, you can use sub on the string.find function. this DOES not perform manipulation on the output, but manipulates wich part of string.find to take.
to get the first number, you could use this: print(string.sub(string.find(string,"this"),1)) outputs 11
to get the second number, you could use this: print(string.sub(string.find(string,"string")+5,1)) outputs 16.
Note the +5. the 5 is the length of the string to search for - 1 ("string" is 6 long, -1 and you get 5)
|
|
|
| Report Abuse |
|
|
ohno1112
|
  |
| Joined: 23 Mar 2013 |
| Total Posts: 833 |
|
|
| 22 Oct 2014 07:56 AM |
oops
to get the first number, you could use this: print(string.sub(string.find(string,"this"),1)) outputs 11
it searches for this. change to "string" and you'd see the result i talked about. |
|
|
| Report Abuse |
|
|