Hey Devforum I want to check a string and get certain parts or information from that string

Hello Devforum,

If the title made no sense let me explain. I want to add information to a string and then get that information out of the string. For example, lets say I have a string name="Lamp" Description="Just a lamp." now I want to use display the name Lamp in a text label and I want to display the description Just a lamp. in a text label how could I do this?

what do you mean exactly? like if somebody toggles over it, or a button? I don’t really understand.

I believe you should use some kind of string manipulation, even though I don’t quite understand your question well

–refers to roblox string pattern api reference

1 Like

Ok thanks for your response I’ll say exactly what I’m trying to do. So I have a string value with the value of name="Lamp" Description="Just a lamp." like this

image
image

now I want to somehow just get the Lamp portion of it run a script that reads the value and sees the name="Lamp" and will return with Lamp

for index in ("name = 'Lamp' description = 'Just a lamp'"):gmatch("()'") do 
  print(index) 
end

I don’t know would this work, but there are several things I recommend you do,

  1. get rid of the double apostrophe, use some other kind of characters, like “_”, “-”, or “~”
  2. therefore you can use string.split() instead, not only much more efficient, but also a lot simpler,
  3. put a “,” or some kind of separator between the name = “Lamp” and description = "Just a lamp"
    so that you can use string.split() again, which is again, much simpler

so something like this

myString = "name-Lamp,description-Just a lamp"
local stringSections = string.split(myString, ",")
print(stringSections[1])
print(stringSections[2])
local lampName = string.split(stringSections[1], "-")[2] -- this might look complicated but trust me it's not

so you split “name-Lamp,description-Just a lamp” into
“name-Lamp” and “description-Just a lamp”
then
“name”, “Lamp”, “description”, “Just a lamp”

I am reading farther into the documentation and I believe I understand it somewhat. The way you mentioned with splitting would work for the first part but then I would still have to actually grab the Lamp and Just a lamp.

You could just make two string values instead of one in the object titled “TitleOfObject” and “DescriptionOfObject”, then manipulate them however you want that way.

It’s not the most efficient way, but it will save you the hassle of trying to understand string manipulation.

You could just use attributes, that way you can give each string their own “instance”
image

well

--if aString = "name-Lamp,description-Just a lamp"
local stringSections = string.split(aString, ",")
--string sections = {"name-Lamp", "description-Just a lamp"}
local string1 = string.split(stringSections[1], "-") -- "name-Lamp" > {"name" "Lamp"}
string1[1] = "name"
string1[2] = "Lamp"

which then you can do the same for the other part of the description bit

--remember that:
stringSections[2] =  -- "description-Just a lamp"
local string2 = string.split(string2, "-")
print(string2[1]) -- "description"
print(string2[2]) -- "Just a lamp"

@NuclearHedgie
Well what im doing is im gonna put this one value in inspectable items then I will make a script that will remove the value save the information and add attributes to the object that will then use them for other scripts this struggle and learning curve will save me a lot of time in the long run.