generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: gsub question

Previous Thread :: Next Thread 
PurelyMystic is not online. PurelyMystic
Joined: 24 May 2010
Total Posts: 931
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
PurelyMystic is not online. PurelyMystic
Joined: 24 May 2010
Total Posts: 931
19 May 2017 01:41 PM
ples send lua


say wat
Report Abuse
Goulstem is not online. 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 is not online. Goulstem
Joined: 04 Jul 2012
Total Posts: 7177
19 May 2017 01:53 PM
nvm I read q wrong yo


Report Abuse
Goulstem is not online. 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
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
19 May 2017 02:09 PM
Goulstem, what is he trying to do? I want to help :c


Report Abuse
Goulstem is not online. 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
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
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
PurelyMystic is not online. PurelyMystic
Joined: 24 May 2010
Total Posts: 931
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 is not online. 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 is not online. 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 is not online. Goulstem
Joined: 04 Jul 2012
Total Posts: 7177
19 May 2017 04:22 PM
^Ayyyyy

this guy ;D


Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image