Im trying to make a kinda advanced saving system and I wanna try to store as much data as I can in 1 string, so I was wondering how would you get the text between some brackets, for example:
local String = “blahblahblah{name}blahblah318048”
How would I get the “name” from that string? I can’t do string.match the name because I don’t have the string of the name to match, so how would I get the text in between the brackets? Thanks!
I actually think I may know how to do this, somehow loop through a string, and make it so if it detects a “{” then add the letters after that to a variable of a empty string, and then stop recording the letter once it detects a “}”, I can just use a switch for when ever it detects a “{” or a “}” and if its true then add the letter after the bracket to the start of a new string, if you guys have any suggestions tell me!
You can just use string.match and get the string in between the brackets.
Example code:
local coolDataString = "aduAWFUAWgAWD{Katrist}2qeqASDWA"
print(string.match(coolDataString, "{.*}"))
if String:find("{") then
String = String:split("{")[2]
if String:find("}") then
String = String:split("}")[1]
print(String)
end
end
Now, I’m not too good at string formats so I can’t provide an answer like @Katrist, but theirs should work.
I would save it as
local StringData = "Data1/Data2/Data3/ect"
then do
local data = string.split(StringData,"/")
then boom, it is turned into a table. Hope this helps
Thanks guys! -----------------
Just wanted to add that the lesser utilised %bxy
string pattern would work for this.
local String = "123{4567}890"
String = string.match(String, "%b{}")
print(String) --{4567}