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.

clearconsole();
treenode obj = Model.find("Shape17");
string a;
string b = "";
obj.alabel = a;

print("a:" + a.length);
print("b:" + b.length);
print("alabel:" + obj.alabel.length);// length of empty string equal to 1 doesn't make sense in FlexScript
print("a=b:" + (a == b));
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.

Steven Chen avatar image Steven Chen commented ·

Oh, I guess obj.alabel.length is not string.length. But it still be confusing.

print("string(alabel):" + obj.alabel.as(string).length);// = 0
0 Likes 0 ·

1 Answer

·
Phil BoBo avatar image
0 Likes"
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.

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.