Jump to content
Robin Withes

How to get a array out of a string.

Recommended Posts

I have to work alot of EXTB3 and me and one of the people i script with are stuck on this (possibly) simple issue.

When we pulled a array out of the database that contains playeruids we noticed it was a string and not a array :

_original = "[`76561197979553832`,`76561198128204387`,`76561198115523495`]";

Could anyone help us out here by turning it into preferrably:

_original = [`76561197979553832`,`76561198128204387`,`76561198115523495`];

We've tried most stuff already including compiling it using toString etc, but nothing seems to work.

Share this post


Link to post
Share on other sites

It seems to be not so easy! Test:

_original = "[`76561197979553832`,`76561198128204387`,`76561198115523495`]";

parseSimpleArray ((_original splitString "'") joinString """");

  • Sad 1

Share this post


Link to post
Share on other sites

As soon as i parse the array it appears to f"ck up the numbers

Example:

 

"[76561197979553832,76561198128204387,76561198115523495]" 
[7.65612e+016,7.65612e+016,7.65612e+016] //after i parse it

 

Share this post


Link to post
Share on other sites

This code worked for me:

it replaces the ` with ' and then compiles it.

_original = "[`76561197979553832`,`76561198128204387`,`76561198115523495`]";
_new = "";
for "_i" from 0 to (count _original - 1) do
{
_c = _original select [_i,1];
if(_c == '`') then { _c = "'"; };
_new = _new + _c;
};

_arr = call compile _new;

player sidechat format["%1", _arr];
player sidechat format["%1", _arr select 0];

 

Share this post


Link to post
Share on other sites

Why not simply:

_array = _original splitString "[`,]";

Which would result in an array of strings: ["76561197979553832","76561198128204387","76561198115523495"]

Or are the ` characters necessary?

  • Like 1

Share this post


Link to post
Share on other sites
2 hours ago, Robin Withes said:

Pasted your exact code and logged the _original var.

Output is in the debug console.

 

https://gyazo.com/d3fafeb11698f504ecdec2d05364eb39

 

 

 

Please play attention on your entry.

_arr = "[`76561197979553832`,`76561198128204387`,`76561198115523495`]";

is not the same as :

_arr = "['76561197979553832','76561198128204387','76561198115523495']"; // apostrophe not the same as grave accent

is not the same as :

_arr = "[76561197979553832,76561198128204387,76561198115523495]"; // without any mark

 

for this last entry, test:

_arr splitString (tostring toarray "[,]")

 

 

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×