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: Remove part of a statement?

Previous Thread :: Next Thread 
Lua_Basics is not online. Lua_Basics
Joined: 04 Jun 2012
Total Posts: 9977
11 Aug 2016 04:04 PM
What I want to do is say I name something:

object-1234

What I want is the numbers, so how would I detect the object in front and remove that..? (Never really done this before)
Report Abuse
GGGGG14 is not online. GGGGG14
Joined: 29 Jan 2012
Total Posts: 25344
11 Aug 2016 04:08 PM
string.gsub

Example code:

print(string.gsub("Hello world","Hello","Goodbye")) -- Output: Goodbye world
Report Abuse
Kodran is not online. Kodran
Joined: 15 Aug 2013
Total Posts: 5330
11 Aug 2016 04:09 PM
roblox filter is great

http://hastebin.com/raw/epelalisug
Report Abuse
Kodran is not online. Kodran
Joined: 15 Aug 2013
Total Posts: 5330
11 Aug 2016 04:10 PM
gmatch returns a function, mine works just print numbers and it prints 1234
Report Abuse
Kodran is not online. Kodran
Joined: 15 Aug 2013
Total Posts: 5330
11 Aug 2016 04:11 PM
Ah, never mind I misread your reply. but gsub isn't what he's looking for either.
Report Abuse
fixylol is not online. fixylol
Joined: 14 Dec 2012
Total Posts: 7412
11 Aug 2016 04:12 PM
print(string.gsub("object-1234","object-",""))

Number of times my opinion changed: Alot.
Report Abuse
Lua_Basics is not online. Lua_Basics
Joined: 04 Jun 2012
Total Posts: 9977
11 Aug 2016 04:12 PM
If I could use:

string.gmatch("Numbers", "b")

But to print the left overs after remove the 'b' kind of thing, then i'd have what I want.
Report Abuse
Lua_Basics is not online. Lua_Basics
Joined: 04 Jun 2012
Total Posts: 9977
11 Aug 2016 04:14 PM
Im using a datastore to store values so just labeling something 'gear-ObjectName' then checking if it has the 'gear-' before it (if statement.) then I can see if the gear is in the storage (after removing the 'gear-') and reward that to the player.
Report Abuse
GGGGG14 is not online. GGGGG14
Joined: 29 Jan 2012
Total Posts: 25344
11 Aug 2016 04:15 PM
local MyString = "test-123"
local FrontPart = MyString:sub(1,MyString:find("%d")-1)


-- idk xD
Report Abuse
GGGGG14 is not online. GGGGG14
Joined: 29 Jan 2012
Total Posts: 25344
11 Aug 2016 04:16 PM
local FrontPart = MyString:sub(1,MyString:find("%d?")-1)
Report Abuse
GGGGG14 is not online. GGGGG14
Joined: 29 Jan 2012
Total Posts: 25344
11 Aug 2016 04:24 PM
local MyString = "test-123"

local Numbers = MyString:sub(MyString:find(MyString:match("%d")),MyString:len())
Report Abuse
GGGGG14 is not online. GGGGG14
Joined: 29 Jan 2012
Total Posts: 25344
11 Aug 2016 04:26 PM
local MyString = "test-123"

to get all of the #'s do:

MyString:match("%d+") -- xD
Report Abuse
Lua_Basics is not online. Lua_Basics
Joined: 04 Jun 2012
Total Posts: 9977
11 Aug 2016 04:28 PM
How would I use that in a if statement to check if the 'gear-' is there (before it..?)
Report Abuse
GGGGG14 is not online. GGGGG14
Joined: 29 Jan 2012
Total Posts: 25344
11 Aug 2016 04:29 PM
im really rusty on string patterns / string manip...
Report Abuse
GGGGG14 is not online. GGGGG14
Joined: 29 Jan 2012
Total Posts: 25344
11 Aug 2016 04:32 PM
@Lua_Basics:

local MyString = "gear-1234" -- or whatever your string is

local function CheckStringForGear(stringArg)
if stringArg:find("gear-") then
local otherPart = stringArg:sub(6,stringArg:len())
return otherPart
else
return print("stringArg didn't have gear- in it.")
end
end

CheckStringForGear(MyString)
Report Abuse
Lua_Basics is not online. Lua_Basics
Joined: 04 Jun 2012
Total Posts: 9977
11 Aug 2016 04:45 PM
I just created another table inside the main one to store the stuff... :3
Report Abuse
Kodran is not online. Kodran
Joined: 15 Aug 2013
Total Posts: 5330
11 Aug 2016 04:52 PM
function findGear(str)
local a, b = str:find("gear%-")
if not a then return nil end
return str:sub(b+1, #str)
end

print(findGear("gear-123412"))
>123412

print(findGear("hat-12345"))
>nil
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