View Full Version : Converting String to Int

8th Sep 2001, 07:35 PM
While i'm here, spamming the board :P

I need to convert a String to an int value. I tried ATOI, the trusty c function, but that gave me crap.

local int i;
local myString;

i = atoi(myString);

It gave me a type error on that. Am i a moron? How is this done in uscript?

Magus {DarkMagic}
8th Sep 2001, 07:44 PM
To convert a string to int try using the function asc(string s)


local int i;
local myString;

i = asc(myString);

8th Sep 2001, 11:18 PM
Thanks a bunch :)

10th Sep 2001, 02:47 AM
For the record it would be:

local string myString;


15th Sep 2001, 07:41 AM
is this better then the

i = int(myString);

or does it make no difference?

15th Sep 2001, 02:34 PM
I'm not sure if there is a real difference - I always just cast strings to ints instead of using atoi(), and I've never had any problems with it.