Is there a way to use part of name to get item in table?

i’m trying to split the string of something in a table but to call the item in the table i only have half the name confirmed and was wondering if their was a way to still get the correct item?

Blockquote

if data ~= nil then
print(data)
for i, v in pairs(DataStuff:GetChildren()) do
print(v)
local Need = tostring(v)
local splitString = string.split(data[Need], “@”)
print(splitString)
local Exp = splitString[2]
print(Exp)
local XpR
local Lvl
end
else
for i, v in pairs(DataStuff:GetChildren()) do
v.Value = 0
end
end

if data ~= nil then
	print(data)
	for i, v in pairs(DataStuff:GetChildren()) do
		print(v)
		local Need = tostring(v)
		local splitString = string.split(data[Need], “@”)
		print(splitString)
		local Exp = splitString[2]
		print(Exp)
		local XpR
		local Lvl
	end
else
	for i, v in pairs(DataStuff:GetChildren()) do
		v.Value = 0
	end
end

I’m fairly certain you have both the name and half the name
Full name: local Need = tostring(v), and (maybe) v
Half name: local splitString = string.split(data[Need], “@”)
Not really sure what you want to accomplish so I’d appreciate if you add more details

basically what i’m doing is getting the name of a variable but to save it i made it one thing so the name and value are split between an @ symbol but to call it i’m trying to know if there’s a way to call it using only the stuff before the @ since it would be unknown

when you call string.split() it returns a table of the string split by whatever you splitted it by (no duh).

Lets say data[Need] = "Water@Door" and you do this:
local splitString = string.split(data[Need], “@”),
splitString should equal {"Water", "Door"}.

Assuming there’s just 1 “@” symbol in data[Need] where it splits the string in half, you should do splitString[1] to access the first half and splitString[2] to get the other half.

When you say

You’d be wrong, since it is known? So unless I’m getting something wrong, I’m pretty sure you still have both the names

example:

the thing I’m trying to find is called swordXp@28

all i know is swordXp@ and i need to call the whole swordXp@28 but i don’t know what the 28 is because it’s the part I’m trying to get when i split it…
what I’m trying to find out is if there is a way to get the whole name using only the swordXp@ because i only learn what’s after the @ once i split it

the issue i’m trying to fix is that when i say local splitString = string.split(data[Need], “@”)
and i’m trying to get swordXp@28, Need in " `local splitString = string.split(data[Need], “@”)" is just swordXp@ because i don’t know what comes after @

Can you fix this last sentence? I think I’m starting to understand it but the last sentence kinda confuses me

String.split returns an array of strings so simply index two of the array and you will get “28” as a string if you need it as a number use the tonumber() function

SplitString = string.split(“swordXp@28”, “@“)[2]

that work?
Need in " `local splitString = string.split(data[Need], “@”)" is just swordXp@ because i don’t know what comes after @