sizeof() on String type with a fixed size of 10

Solution Available
Raz A.
Haifa,

Apr 22, 2019
82 Posts

1  |  0  

Re: sizeof() on String type with a fixed size of 10

I have a String type which is named "sStr" with a fixed size of 10.

When i use sizeof(sStr) i get "4".

Why?

Jason D.
Irvine, CA

Apr 22, 2019
32 Posts

0  |  0  

Re: sizeof() on String type with a fixed size of 10

Hi Raz,

sizeof() is returning the size of the pointer that is pointing to the buffer containing the string.

To get the number of characters in the buffer you can use the len() procedure.

Regards,
Jason

Raz A.
Haifa,

Apr 23, 2019
82 Posts

0  |  0  

Re: sizeof() on String type with a fixed size of 10

Hi,
if i dont initiale the sStr variable, the len() function returns 0.

how can i get the "fixed size" of the variable?

DrATEasy (Ron Y.)
Mission Viejo, CA

Apr 23, 2019
367 Posts

0  |  0  

Re: sizeof() on String type with a fixed size of 10

Define it fixed string in the Variable Properties window, see on-line help "String Data Types" topic.

Raz A.
Haifa,

Apr 23, 2019
82 Posts

0  |  0  

Re: sizeof() on String type with a fixed size of 10

Thats what i did. And still i get 0.


See attached file.


File Attachment:
len().JPG

Raz A.
Haifa,

Apr 24, 2019
82 Posts

0  |  0  

Re: sizeof() on String type with a fixed size of 10

Attached file again (prev file link dosent work)


File Attachment:
len.JPG

DrATEasy (Ron Y.)
Mission Viejo, CA

Apr 24, 2019
367 Posts

0  |  0  

Re: sizeof() on String type with a fixed size of 10

Len() returns the current length so it will be zero until you assign to it a string, sizeof returns the number of bytes that this variable takes - that will be always 4 for a string. You can also use array of char:

acChars: char [100]

print sizeof acChars

will print 100



Please Note
You need to have a M@GIC account to participate in the Forums.
Not yet registered on our website? Click here to register today!

All content, information and opinions presented on the Marvin Test Solutions User Forums are those of the authors of the posts and messages and not Marvin Test Solutions'. All attachments and files are downloaded at your own risk. [Read More]