Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Getting the ID from a link?

Asked by
RoyMer 301 Moderation Voter
8 years ago

How would I get the ID from this link? (By string manipulation ofc)

https://www.roblox.com/item.aspx?seoname=Dragon-Hunter-Armor&id=134111557

What pattern is the = symbol considered?

3 answers

Log in to vote
2
Answered by
Sublimus 992 Moderation Voter
8 years ago

You can use string.find and string.sub to do this. I'll explain as I go

local string = "https://www.roblox.com/item.aspx?seoname=Dragon-Hunter-Armor&id=134111557"
-- Store the string

local start,en = string.find(string, "id=",1, true)
-- String.find returns two numbers, where the string you are trying to find starts, and where it ends, so we are storing these two values into "start", and "en".
-- The parameters then go string.find(ContainingString, letters/string to find, index of where to start, true).  True keeps them from being read as anything other than normal text.

local id = string.sub(string, en + 1)
-- We will then use substring to cut from the end of the pattern to the end of the string, since the id is last.
-- Substring goes string.sub(StringToCut, StartingPosition, EndingPosition) and since we did no ending position, it will go from where it started all the way to the end by default.

If you need any other clarification, let me know.

0
Thanks a lot for the detailed explanation! RoyMer 301 — 8y
0
No problem! Sublimus 992 — 8y
Ad
Log in to vote
1
Answered by
M39a9am3R 3210 Moderation Voter Community Moderator
8 years ago

You could use string patterns and do string.match("https://www.roblox.com/item.aspx?seoname=Dragon-Hunter-Armor&id=134111557", ".*&id=(%d+)").

The match function will go through the string with the string pattern and it will go through all characters being the pattern .*, at least until it gets to "&id=" then the function might actually start to care. The . indicates that the character can be any character while the * is used to match 0 or more characters, once again at least until we get to the &id= part.

Since we placed %d+ in parenthesis in the pattern, the script is keeping an eye out for digits any number between 0 and 9. %d is a character class the % telling the script to listen up, the d being for digits. Since we placed a + sign, that means the script should try to match at least 1 character that is a digit after the &id=.

There you have it, the function will return the string that was recognized so you can set it to a variable.


Hopefully this answered your question, if so please hit the accept answer button. If you have any questions, feel free to comment below.
0
Thanks! RoyMer 301 — 8y
Log in to vote
-1
Answered by 8 years ago

The ID for the item would be. 134111557

'id=134111557'

0
I know but I wish to manipulate the string by string patterns but I'm a bit confused. RoyMer 301 — 8y

Answer this question