generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Is this possible? Complicated.

Previous Thread :: Next Thread 
96mg is not online. 96mg
Joined: 15 May 2017
Total Posts: 775
23 Jul 2017 01:18 PM
I want to convert a string to a table.
I've got the table from a Website, and it it's kind of complicated.

The table consists of

Table > String

The String is the Actual Table.

Example :
Test = [{"[{Hello},{WhatsUp}]"}]

So when I print : Test[1] it says : [{"[{Hello},{WhatsUp}]"}]

Is there a way to get the string "[{"[{Hello},{WhatsUp}]"}]" to be an Actual Table itself?




wunt s0m3 b0rk?
Report Abuse
PLBH is not online. PLBH
Joined: 08 May 2014
Total Posts: 151
23 Jul 2017 01:38 PM
table.insert(Test, 1, "[{Hello},{WhatsUp}]") ?
Report Abuse
96mg is not online. 96mg
Joined: 15 May 2017
Total Posts: 775
23 Jul 2017 01:41 PM
I want to convert the string to a table, not insert it into one


wunt s0m3 b0rk?
Report Abuse
PLBH is not online. PLBH
Joined: 08 May 2014
Total Posts: 151
23 Jul 2017 01:45 PM
Test = table.concat({" [{"[{Hello},{WhatsUp}]"}] "})
print(Test)
Report Abuse
DivinePheonix is not online. DivinePheonix
Joined: 30 Mar 2011
Total Posts: 11190
23 Jul 2017 01:46 PM
Just do what the first guy suggested

or if possible: http://wiki.roblox.com/index.php?title=API:Class/HttpService/JSONDecode
Report Abuse
96mg is not online. 96mg
Joined: 15 May 2017
Total Posts: 775
23 Jul 2017 01:50 PM
That's making the table a string.
Im aiming for the opposite


wunt s0m3 b0rk?
Report Abuse
LaeMVP is online. LaeMVP
Joined: 24 Jun 2013
Total Posts: 4416
23 Jul 2017 01:50 PM
If it is a JSON string you could just JSONDecode it
Report Abuse
LaeMVP is online. LaeMVP
Joined: 24 Jun 2013
Total Posts: 4416
23 Jul 2017 01:51 PM
or i don't think it needs to be a json idk
Report Abuse
96mg is not online. 96mg
Joined: 15 May 2017
Total Posts: 775
23 Jul 2017 01:52 PM
It is, and I've tried that, but It seems to act funky.

I'll try it again


wunt s0m3 b0rk?
Report Abuse
BaiYuni is not online. BaiYuni
Joined: 09 Oct 2009
Total Posts: 2861
23 Jul 2017 01:52 PM
I'm not quite sure, but you can possibly get what's in the string and maybe you can create your own table?

Test = {"[\"Hello\"],[\"WhatsUp\"]"}

for tab in Test[1]:gmatch("%b[]") do
table.insert(Test, tab)
end

Test["Hello"] = {}
Test["WhatsUp"] = {}


table.insert(Test["Hello"], "hiya")
print(Test["Hello"][1])

Should correct me if I'm wrong on going about this.
Report Abuse
crazyman32 is not online. crazyman32
Joined: 13 Apr 2008
Total Posts: 18027
23 Jul 2017 01:52 PM
Yeah, encoding/decoding JSON would work. That's the best way to go between a table and a string.

But if you have something really simple, like a comma-separated value list (CSV), you could do something like this:


local myStr = "Hello,Apple,Test,XYZ"

function ToString(tbl)
return table.concat(tbl, ",")
end

function ToTable(str)
local tbl = {}
for item in str:gmatch("[^,]+") do
table.insert(tbl, item)
end
return tbl
end

local myTbl = ToTable(myStr)
-- Test:
print("Same:", myStr == ToString(myTbl))
Report Abuse
BunnyBoy26 is not online. BunnyBoy26
Joined: 17 Jun 2010
Total Posts: 5674
23 Jul 2017 02:33 PM
Alright, I just wrote this up now and traced is with the given example manually, so no guarantees. I also hope the order isn't important.


Test = "{{Hey, {Everyone}}, WhatsUp, {}, {{Hows, {It}, Going?}}}"
result = {}

function ParseStringToTable(t,str)
local mstr = str:match("^{(.*)}$")
if mstr then -- should always pass, actually
for w in mstr:gmatch("[^,]*") do
if not w:match("[{}]") then
t[#t+1] = w
end
end
for w in mstr:gmatch("%b{}") do
t[#t+1] = {}
ParseStringToTable(t[#t],w)
end
end
return t
end

ParseStringToTable(result,Test)

--> result = {"WhatsUp", {"Hey", {"Everyone"} } , {""} , { { "Hows", "Going?", {"It"}}}}}
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image