Simply Maya User Community

Simply Maya User Community (https://simplymaya.com/forum/index.php)
-   Programming (https://simplymaya.com/forum/forumdisplay.php?f=32)
-   -   String to Int (https://simplymaya.com/forum/showthread.php?t=20873)

mayakid14 29-03-2006 02:57 AM

String to Int
 
Does anyone know if there is a way to convert a string to an int or a float.
Example:

string $mystring = "15";
int $myint = ($mystring - 1);
print $myint;

Maya doesn't execute this script because $mystring doesn't really have a int value. In BASIC I think this concept would be written as:
Dim mystring As string = "15"
Dim myint As integer = (val(mystring) - 1)
MsgBox(myint)
The VAL function works in BASIC but it won't work in MEL. Of course it doesn't seem like MEL hasa VAL function but is there an alternative?

Alan 29-03-2006 09:23 AM

you're talking about casting.

you can cast a string like this:

string $strVal = "150000";
int $intVal = (int)$strVal;
float $floatVal = (float)$strVal;


and you can go the other way too:

int $intVal = 1545;
string $strVal = (string)$intVal;

:ninja:
A

mayakid14 29-03-2006 02:35 PM

Whoa thanks a bunch. Never thought there would be a way for this. Couldn't find anything in the reference commands or anything.
:beer: You're Awsome:beer:

Alan 29-03-2006 03:12 PM

no problem. Casting is common in many programming languages.

:ninja:
A


All times are GMT. The time now is 11:08 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Simply Maya 2018