Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Explicit TypeCasting Q?

JackBurton Faulkland
PorkChop Express
Join date: 3 Sep 2005
Posts: 478
11-09-2005 12:55
When Type casting a string to an int int the form:

string myString = "1";
integer x;

x = (integer)myString;

what value will x have and how does LSL interpret string to integer exlpicit typecasting?
_____________________
You know what Jack Burton always says... what the hell?
Jokey Domela
Registered User
Join date: 27 Jul 2005
Posts: 83
11-09-2005 13:56
x=1

string numbers will always convert properly to integer.

Also,

string myString = "boogers";
integer x;

will result in x=0 if memory serves correctly.
Zodiakos Absolute
With a a dash of lemon.
Join date: 6 Jun 2005
Posts: 282
11-09-2005 13:58
Hmm, I'll run some tests later, I'd love to know what strings like "1 12 53" and "x324" will typcast to integer as.
JackBurton Faulkland
PorkChop Express
Join date: 3 Sep 2005
Posts: 478
11-09-2005 14:00
thats what i was hoping for i am at work and unable to test so thanks much for yer answer :)
_____________________
You know what Jack Burton always says... what the hell?
Jokey Domela
Registered User
Join date: 27 Jul 2005
Posts: 83
11-09-2005 14:05
From: Zodiakos Absolute
Hmm, I'll run some tests later, I'd love to know what strings like "1 12 53" and "x324" will typcast to integer as.


if a string starts with an integer, you get the integer and the text is ignored...IE:

string myString = "5 dfssdf";
integer x;
x = (integer)myString;

x=5


if you have multiple numbers, only numbers up to the 1st space are typecast IE:

string myString = "2 34 567";
integer x;
x = (integer)myString;

x=2

all text is always 0, even if numerics follow IE:

string myString = "snot5323";
integer x;
x = (integer)myString;

x=0
Zodiakos Absolute
With a a dash of lemon.
Join date: 6 Jun 2005
Posts: 282
11-09-2005 19:18
Oh wow, thank you very much for the response! I hadn't yet gotten to test it, but I don't think I'll need to now, hehe. :D
Jesrad Seraph
Nonsense
Join date: 11 Dec 2004
Posts: 1,463
11-10-2005 02:17
Even better, you can specify numbers in other formats as well, like hex:

string myString = "0x10";
integer x;
x = (integer)myString;

x=16
_____________________
Either Man can enjoy universal freedom, or Man cannot. If it is possible then everyone can act freely if they don't stop anyone else from doing same. If it is not possible, then conflict will arise anyway so punch those that try to stop you. In conclusion the only strategy that wins in all cases is that of doing what you want against all adversity, as long as you respect that right in others.