VEX: len(string) not valued properly when quotes in string?

   2741   3   2
User Avatar
Member
192 posts
Joined: April 2015
Offline
Hi guys,

I'm using double quotes in a string in VEX, which works.
However when using the len(str) function, it does not count it properly.
It counts three characters for each
"

Is this to be expected somehow? Or is it a bug?

Thanks ya

Attachments:
Screenshot 2021-10-15 at 18.52.01.png (16.7 KB)
doublequotes string length.hiplc (146.5 KB)

User Avatar
Member
405 posts
Joined: April 2017
Offline
If you check the docs for len(), when used on a string it's returning the number of bytes in the string, not the number of characters. For basic ASCII characters you'll get the number of characters, but your fancy quotation marks there aren't ASCII and so there's more bytes used. You're probably better off using Python to get the lengths of the strings, and storing that as an attribute to be manipulated later in VEX.
MOPs (Motion Operators for Houdini): http://www.motionoperators.com [www.motionoperators.com]
User Avatar
Member
192 posts
Joined: April 2015
Offline
Thanks again, toadstorm.
User Avatar
Member
9383 posts
Joined: July 2007
Offline
but there is also a question whether you are using those fancy quotes on purpose or you could have just used normal ones like instead of this (which is in your file):
s@str = "“hoe”";
i@str_len = len(s@str);

you can maybe use this:
s@str = '"hoe"';
i@str_len = len(s@str);
which would result in correct count of 5

also escaping the quote would work, but may not read as clean:
s@str = "\"hoe\"";
i@str_len = len(s@str);
Edited by tamte - Oct. 15, 2021 14:11:35
Tomas Slancik
CG Supervisor
Framestore, NY
  • Quick Links