|
| 19 May 2017 01:29 PM |
So I am reading about it, how would I get the sub() position after finding a match? Using for i=1, #string do and then the string.gmatch() etc,. Or is there something different?
say wat |
|
|
| Report Abuse |
|
|
| |
|
Goulstem
|
  |
| Joined: 04 Jul 2012 |
| Total Posts: 7177 |
|
|
| 19 May 2017 01:52 PM |
You can use the 'find' function, after you actually find your substring, to determine where in the string said substring was located:
local str = "Hell00 world"; local matched = str:match("%d+"); print(str:find(matched)); --> 5,6
|
|
|
| Report Abuse |
|
|
Goulstem
|
  |
| Joined: 04 Jul 2012 |
| Total Posts: 7177 |
|
| |
|
Goulstem
|
  |
| Joined: 04 Jul 2012 |
| Total Posts: 7177 |
|
|
| 19 May 2017 02:08 PM |
I guess you could search for matches of what gsub replaced?
local str = "Hell00 world"; local pattern = "%d+"; local replace = "[num]" local substr = str:gsub(pattern,replace);
for i in str:gmatch(pattern) do s1, s2 = string.find(str,i); print(i.." was replaced from the string: "..str.." at "..s1.."|"..s2); end
|
|
|
| Report Abuse |
|
|
|
| 19 May 2017 02:09 PM |
Goulstem, what is he trying to do? I want to help :c
|
|
|
| Report Abuse |
|
|
Goulstem
|
  |
| Joined: 04 Jul 2012 |
| Total Posts: 7177 |
|
|
| 19 May 2017 02:20 PM |
I (think) he wants to know what places in a string gsub is changing according to the given pattern?
|
|
|
| Report Abuse |
|
|
|
| 19 May 2017 02:23 PM |
I see. I had an idea but I really don't know. I think he wants to know the positions too.
|
|
|
| Report Abuse |
|
|
|
| 19 May 2017 03:40 PM |
Here is what I'm trying to do String = "what so ok" I want it to say the position for each space. So space 1 is String:sub(5) and etc,.
say wat |
|
|
| Report Abuse |
|
|
Goulstem
|
  |
| Joined: 04 Jul 2012 |
| Total Posts: 7177 |
|
|
| 19 May 2017 04:18 PM |
local str,count = "what so ok",false;
for i = 1,#str do if str:sub(i,i) == " " then print("A space was found in the string at "..i); end end
|
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 19 May 2017 04:20 PM |
"I want it to say the position for each space. So space 1 is String:sub(5) and etc,." for pos in str:gmatch("()%s") do print(pos) end |
|
|
| Report Abuse |
|
|
Goulstem
|
  |
| Joined: 04 Jul 2012 |
| Total Posts: 7177 |
|
| |
|