TimeTicks
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
|
| 21 May 2016 02:04 PM |
returning the index given one of the characters?
Example:
somestring = "abcdefgh"
somestring["b"] == 2
is it string.sub ? |
|
|
| Report Abuse |
|
|
Skellobit
|
  |
| Joined: 13 Apr 2016 |
| Total Posts: 12758 |
|
|
| 21 May 2016 02:07 PM |
print(string.find("abcdefgh", "b"))
> 2 2
it returns the position of the FIRST found string within the whole string
Formerly ToxicDominator - add 17,509 posts |
|
|
| Report Abuse |
|
|
| |
|
TimeTicks
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
|
| 21 May 2016 02:08 PM |
| forgot it returned a number. Thanks |
|
|
| Report Abuse |
|
|
Skellobit
|
  |
| Joined: 13 Apr 2016 |
| Total Posts: 12758 |
|
|
| 21 May 2016 02:12 PM |
use this so it doesn't return 2 2 print(tostring(string.find("abcdefghb", "b")):sub(1))
Formerly ToxicDominator - add 17,509 posts |
|
|
| Report Abuse |
|
|
|
| 21 May 2016 02:14 PM |
"use this so it doesn't return 2 2" ":sub(1))" That doesn't help. Firstly, it returns two numbers, not one string.
local Start, End = string.find(...)
Secondly, sub(1) would return all of the letters anyways since using it with one argument returns from that argument until the end of the string.
|
|
|
| Report Abuse |
|
|
Skellobit
|
  |
| Joined: 13 Apr 2016 |
| Total Posts: 12758 |
|
|
| 21 May 2016 02:18 PM |
I'm talking about using it for purposes that having a variable hold 2 numbers wouldn't work. If you want a number, you would just use:
tonumber(tostring(string.find("abcdefghb", "b")):sub(1))
I'm not really sure what you're talking about, but that returns 2 as a number
Formerly ToxicDominator - add 17,509 posts |
|
|
| Report Abuse |
|
|
12103net
|
  |
| Joined: 08 Jul 2013 |
| Total Posts: 350 |
|
|
| 21 May 2016 02:19 PM |
i just made something do you like it
function returnStringPlaces(strin, findwhat) local indexes={} local total=0 repeat wait() if strin:find(findwhat)~=nil then indexes[#indexes+1]=strin:find(findwhat)+total total=total+strin:find(findwhat) strin=strin:sub(strin:find(findwhat)+1) else break end until strin:find(findwhat)==nil return indexes end print(unpack(returnStringPlaces('bobbyhadacowbbfdb', 'b'))) |
|
|
| Report Abuse |
|
|
|
| 21 May 2016 02:22 PM |
It returns 2, 2, not "2 2".
It returns a tuple, two numbers.
Tuples don't work that way.
|
|
|
| Report Abuse |
|
|
12103net
|
  |
| Joined: 08 Jul 2013 |
| Total Posts: 350 |
|
| |
|
Skellobit
|
  |
| Joined: 13 Apr 2016 |
| Total Posts: 12758 |
|
|
| 21 May 2016 02:28 PM |
and that's exactly why I used tostring() so I can manipulate it with string.sub() as if it were a string. then I could retransform it to a number
I have a feeling you still haven't tested this;
print(tonumber(tostring(string.find("abcdefghb", "b")):sub(1)) + 5) >> 7
Formerly ToxicDominator - add 17,509 posts |
|
|
| Report Abuse |
|
|
12103net
|
  |
| Joined: 08 Jul 2013 |
| Total Posts: 350 |
|
|
| 21 May 2016 02:31 PM |
| skello why would you do this |
|
|
| Report Abuse |
|
|
12103net
|
  |
| Joined: 08 Jul 2013 |
| Total Posts: 350 |
|
|
| 21 May 2016 02:32 PM |
lol all you have to do is
a=string.find("abcdefghb", "b") print(a)
jesus
holy crap
way to overcomplicate it dude |
|
|
| Report Abuse |
|
|
TimeTicks
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
|
| 21 May 2016 02:36 PM |
| okay skids. This thread has already closed since the solution has already been mentioned. Go away. |
|
|
| Report Abuse |
|
|
|
| 21 May 2016 02:37 PM |
Okay then, Skello. Your substringing still returns the whole string. With only one argument, it returns from that argument to the end of the string.
try this: print(tostring(string.sub("lol", "o")))
My point is, that is totally unnecessary, you need to learn how tuples work Skello.
|
|
|
| Report Abuse |
|
|
12103net
|
  |
| Joined: 08 Jul 2013 |
| Total Posts: 350 |
|
|
| 21 May 2016 02:58 PM |
"okay skids. This thread has already closed since the solution has already been mentioned. Go away."
ok sir mind your manners you're the one who was begging for something _really_ simple and then you decide to be rude about it when you've got what you want? lol, you're the skid buddy because obviously you're too stupid to know string manipulation |
|
|
| Report Abuse |
|
|