String to int and int to sting conversion

BlitzMax Forums/BlitzMax Beginners Area/String to int and int to sting conversion

Dr. Wildrick(Posted 2006) [#1]
Hi,
I'm a little confused about converting between types, as a result I get error messages that say "Can not convert String to Int" and the like.
I use Superstrict for all my programs in case that make a diffrence.
But If someone could cast some light on converting between strings to int and strings to floats and the other way around - I would be most gratefull.
DW


gman(Posted 2006) [#2]
greetings :) the String class has several built-in functions for converting. check out the Language -> Strings section in the manual for a full list. a quick partial:

String.FromInt()
String.FromFloat()
String.ToInt()
String.ToFloat()


assari(Posted 2006) [#3]
you need to post some codes so we can help


Marmoth(Posted 2006) [#4]
I have the same problem:

What i want to do is to turn a int number (for example 14 ) to the string "14", in order to use it to get an image. An example:

---code---

global tankimagenumber:int=14

global tankimagestring:string

tankimagestring.Fromint(tankimagenumber)

global tankimage:TImage=loadimage("images/tank"+tankimagestring+".png",MASKEDIMAGE) 'knowing that the image file's url is "images/tank14.png"

---end of code---

This doesn't work... what should i do?


skidracer(Posted 2006) [#5]
try tankimagestring=String.Fromint(tankimagenumber)

or utilizing blitzmax auto conversion rules:

tankimagestring=tankimagenumber


Marmoth(Posted 2006) [#6]
Your first solution works (i didn't try the other).

Thanks a lot!


Yan(Posted 2006) [#7]
@Marmoth - You cold just use...
global tankimage:TImage=loadimage("images/tank" + tankimagenumber + ".png",MASKEDIMAGE)