So, let’s say I have a string value, this string value being the image id of something (this is a random number but whatever)
“rbxassetid://89803213”
Now, what if I wanted to convert only the number part to an int value?
I don’t believe you can But I might be wrong
Use string.sub
?
string.sub(idString, 14, -1)
im afraid i have
no idea
what you just did lol
string.sub
just returns a string between the given characters. Lets take an example.
local gamerString = "engineer"
string.sub(gamerString, 1, 4)
would return a string starting with the first character of the string, ending with the 4th character of the string.
so it would return engi?
is the third parameter defaulted to the last part of the string? if so, since rbxassetid:// will always be the same amount of characters, could i just say string.sub(imageid, 14)?
his works but doesn’t convert to a number. you can use tonumber.
tonumber(string.sub(idString, 14, -1))
you might also find this way more convenient
tonumber(string.match(idString, "%d+"))
I’m not sure if string ids have a fix length, but I wouldn’t bet on that being the case.
the third paramater of string.sub() will default to -1, which indeed means that it will go till the end of the string
yeah, i thought about doing that eventually with the tonumber
now, what does the %d+ mean?
Oh this post here might help
https://developer.roblox.com/en-us/articles/string-patterns-reference
%d
means number. +
means one or more.
%d will match a number and the + is there to let you match multiple characters of numbers
so then in theory tonumber(string.sub(myString, 14)) should work?
Yes. It should yea yea, it will work