String to int and int to sting conversion
BlitzMax Forums/BlitzMax Beginners Area/String to int and int to sting conversion
| ||
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 |
| ||
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() |
| ||
you need to post some codes so we can help |
| ||
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? |
| ||
try tankimagestring=String.Fromint(tankimagenumber) or utilizing blitzmax auto conversion rules: tankimagestring=tankimagenumber |
| ||
Your first solution works (i didn't try the other). Thanks a lot! |
| ||
@Marmoth - You cold just use...global tankimage:TImage=loadimage("images/tank" + tankimagenumber + ".png",MASKEDIMAGE) |