question

ksugai avatar image
0 Likes"
ksugai asked ksugai commented

How to convert datatype from array/bundle to string

I am trying to display the label value as a string.

image.jpg

Please tell me how to convert an array which has pointers and arrays as elements to string .

FlexSim 23.0.13
stringdatatype
image.jpg (92.6 KiB)
· 6
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

ksugai avatar image ksugai commented ·

Let me add details to my previous question.

I want to output nodes whose contents are Array or Bundle as if they were viewed on a tree display screen.

LabelSetteing.jpg

LabelDisplayed.jpg

0 Likes 0 ·
labelsetteing.jpg (59.8 KiB)
labeldisplayed.jpg (31.3 KiB)
Joerg Vogel avatar image Joerg Vogel commented ·
@KSugai, where would you display those elements? A dashboard, a graphical user interface or by window pop up showing a part of a sub tree of nodes?
0 Likes 0 ·
ksugai avatar image ksugai Joerg Vogel commented ·

I would like to store them in a bundle table node on the tree and display them on the GUI.

0 Likes 0 ·
Jason Lightfoot avatar image Jason Lightfoot ♦ ksugai commented ·
You can point the table widget to the bundle table - doesn't that work for you? Post an example if not, explaining in more detail what you've like to see, vs. what is shown.
0 Likes 0 ·
Jason Lightfoot avatar image Jason Lightfoot ♦ commented ·

Hi @ksugai,

We haven't heard back from you. Were you able to solve your problem? If so, please add and accept an answer to let others know the solution. Or please respond to the previous comment so that we can continue to help you.

If we don't hear back in the next 3 business days, we'll assume you were able to solve your problem and we'll close this case in our tracker. You can always comment back at any time to reopen your question, or you can contact your local FlexSim distributor for phone or email help.

0 Likes 0 ·
ksugai avatar image ksugai Jason Lightfoot ♦ commented ·

Sorry for the late reply due to the company being closed during the year-end and New Year holidays.

What I really want to do is store Array or Table type information in a bundle cell.

I know that Array or Table type can be directly stored in a non-bundle table. However, I would like to store them somehow in a bundle table since the data table may contain hundreds of thousands of rows.

To do this, I am thinking of converting Array and Table to string and storing them in bundle cells in the format that is displayed when returning Array or Table in the script console.

image.jpg

I would like to know if there is an easy way to convert data to string like this.

0 Likes 0 ·
image.jpg (11.0 KiB)

1 Answer

·
Jason Lightfoot avatar image
1 Like"
Jason Lightfoot answered ksugai commented

You can try using the JSON methods:

Array test=[1,2,3];
return JSON.stringify(test);

and

string s="[1,2,3]";
return JSON.parse(s);


· 3
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

ksugai avatar image ksugai commented ·

Thank you for your reply.

I tried JSON methods and found that ASCII characters can be converted to string as intended.

However, multibyte characters are converted to Unicode escape sequences.image.jpg

I understand that it can be restored with JSON.parse(), but I would like the user to be able to understand the contents by just looking at the string.

If there is a way to convert multibyte characters to string, please let me know.

0 Likes 0 ·
image.jpg (23.0 KiB)
Jason Lightfoot avatar image Jason Lightfoot ♦ ksugai commented ·

You could concatenate with a delimeter into a single string to store in the bundle

Array a=["a","b","c"];
return a.join(",");   //  "a,b,c"

and then when you need the array of values use the string method 'split' to generate the array.

string s="a,b,c";
return s.split(",");   //  ["a","b","c"]
0 Likes 0 ·
ksugai avatar image ksugai Jason Lightfoot ♦ commented ·

Thank you for your reply.

I was able to display the string as intended.

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.