question

Steven Chen avatar image
0 Likes"
Steven Chen asked Phil BoBo answered

Length of Empty String in Label

Hello,

I found that doesn't make sense to me that empty string label length is 1.

  1. clearconsole();
  2. treenode obj = Model.find("Shape17");
  3. string a;
  4. string b = "";
  5. obj.alabel = a;
  6.  
  7. print("a:" + a.length);
  8. print("b:" + b.length);
  9. print("alabel:" + obj.alabel.length);// length of empty string equal to 1 doesn't make sense in FlexScript
  10. print("a=b:" + (a == b));
  11. print("a=alabel:" + (a == obj.alabel)

empty_string_length_v22.1.fsm

FlexSim 22.1.0
labelsstring
· 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.

1 Answer

Phil BoBo avatar image
1 Like"
Phil BoBo answered

When you access a label, you get a Variant back, not a string.

Variant.length is array length. For a single value, that's 1. FlexScript Class - Variant (flexsim.com)

string.length is the number of characters in a string. To get string length, you need to cast to a string using .as(string) or assigning the value to a string variable. FlexScript Class - string (flexsim.com)

5 |100000

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