question

Ankur A3 avatar image
0 Likes"
Ankur A3 asked Jeanette F commented

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

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!

FlexSim 21.0.10
hctextobject name
1654253207312.png (13.6 KiB)
· 1
5 |100000

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

Jeanette F avatar image Jeanette F ♦♦ commented ·

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 0 ·

1 Answer

·
Matthew Gillespie avatar image
0 Likes"
Matthew Gillespie answered

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];
5 |100000

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

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.