How to extract partial object name to refer global table name?

How to extract partial object name to refer global table name?

rajankur6494
Advocate Advocate
11 Views
2 Replies
Message 1 of 3

How to extract partial object name to refer global table name?

rajankur6494
Advocate
Advocate

[ FlexSim 21.0.10 ]

Hi Team,

I have 10 objects as below:

Obj1_Chair, Obj2_Chair............................................................Obj10_Chair

These objects are having label names as Time_In, Time_Out

I also have global tables related to these objects as below:

Obj1_GlobalTable, Obj2_GlobalTable.........................................................Obj10_GlobalTable

I want to create generic logic for with these object by passing object names (Obj1, Obj2.................Obj10) as loop value.

1654253207312.png

How can I refer global table name since I have to exclude chair from Object name?

Thank you!

0 Likes
Accepted solutions (1)
12 Views
2 Replies
Replies (2)
Message 2 of 3

Matthew_Gillespie
Autodesk
Autodesk
Accepted solution

There are a lot of different ways to do this. Here are some examples:

String Replace

If you know all the objects end with a specific string you can replace that string with a blank string:

string name = "Obj1_Chair";
return name.replace("_Chair", "");

String Replace with Regular Expression

If you want to generically remove the underscore and any characters after it you can use a regular expression that matches the pattern "an underscore followed by any number of other characters":

string name = "Obj1_Chair";
return name.replace(/_.*/, "");

String Split

You could also use the string.split() method to split the string into an array of substrings using the underscore as the delimiter:

string name = "Obj1_Chair";
return name.split("_")[1];


Matthew Gillespie
FlexSim Software Developer

0 Likes
Message 3 of 3

Jeanette_Fullmer
Community Manager
Community Manager

Hi @Ankur A3, was Matthew Gillespie's answer helpful? If so, please click the "Accept" button at the bottom of their answer. Or if you still have questions, add a comment and we'll continue the conversation.

If we haven't heard back from you within 3 business days we'll auto-accept an answer, but you can always unaccept and comment back to reopen your question.

0 Likes