|
| 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
|
  |
| 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
|
  |
| 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
|
  |
| 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
|
  |
| 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
|
  |
| 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 |
|
|
|
| 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 |
|
|
|
| 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
|
  |
| 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
|
  |
| 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
|
  |
| 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
|
  |
| 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 |
|
|
|
| 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
|
  |
| Joined: 29 Jan 2012 |
| Total Posts: 25344 |
|
|
| 11 Aug 2016 04:29 PM |
| im really rusty on string patterns / string manip... |
|
|
| Report Abuse |
|
|
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 |
|
|
|
| 11 Aug 2016 04:45 PM |
| I just created another table inside the main one to store the stuff... :3 |
|
|
| Report Abuse |
|
|
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 |
|
|