PDA

View Full Version : count characters in string?


cgbeige
08-17-2012, 01:44 AM
I'm sure this is one of those python MEL mismashes but I haven't wrapped my head around the syntax of Python within MEL. How do you get the value 5 as a MEL int from this equivalent Python code:

x = "51515"
print len(x)

NateH
08-17-2012, 02:24 AM
Not sure exactly the question but I'll take a stab anyways... :eek:

Length of string via python from mel

string $var = "51515151";
float $length = python("'"+$var+"'");

Or maybe this is what you were asking for?
number = int("51515151")
Or maybe this?
fives = "5151515151".count("5")
Hopefully one of these answers your question..

cgbeige
08-17-2012, 02:33 AM
sorry - I think you misunderstood. I want to get the character count. All those just return the integer. It can be done with MEL but I just know that you can use len in Python to get that. The number I used is irrelevant - I just want to store the number padding as an integer

bk3d
08-17-2012, 03:42 AM
its pretty simple

int $Count = `size "219387456172894";

cgbeige
08-17-2012, 03:54 AM
its pretty simple

int $Count = `size "219387456172894";

perfect - thanks

CGTalk Moderation
08-17-2012, 03:54 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.