int to string, string to int?

BlitzMax Forums/BlitzMax Beginners Area/int to string, string to int?

Garrett(Posted 2006) [#1]
Greetings,

I can't seem to figure out how to convert between strings and integer variables
and vice versa.

Can someone please point me in the right direction?

Thanks,
-Garrett


Perturbatio(Posted 2006) [#2]
Local s:String = "1"
Local g:Int

g= s.toInt()
Print g
g:+ 2
s = g
Print s



Garrett(Posted 2006) [#3]
So toInt() and toString()?

Arf! I was looking for Int() and Str(). :-)

Thanks a bunch,
-Garrett


Perturbatio(Posted 2006) [#4]
take a look in the help under language->strings for all the methods.


Yan(Posted 2006) [#5]
newInt% = oldStr$.ToInt()
newInt% = Int(oldStr$)

newStr$ = oldInt%
newStr$ = String.FromInt(oldInt%)
newStr$ = String(oldInt%)



Garrett(Posted 2006) [#6]
Anybody know what module is related to the toInt() ?

Thanks,
-Garrett


Garrett(Posted 2006) [#7]
Nevermind, don't need to know the module.

Thanks,
-Garrett


Perturbatio(Posted 2006) [#8]
brl.blitz contains the string declaration (in C).


Jesse(Posted 2006) [#9]
Yan: thats good but you forgot to mention wich one you prefer. I am shure one of those is the fastest for in game operations. DO you know? or will my I have to figure it out? :)


H&K(Posted 2006) [#10]
Jesse without running any of them my money is on

newStr$ = String.FromInt(oldInt%) and
newInt% = oldStr$.ToInt() as being the fastest


Yan(Posted 2006) [#11]
I tend to use...
newInt% = Int(oldStr$)
newStr$ = oldInt%
...But only cos I'm comfortable doing it that way.

I'm pretty sure that any difference in speed, if indeed there is any (I've got a feeling they're exactly the same when compiled), is far too slight to be worth worrying about.