local myInt:integer=myString$ ?
BlitzMax Forums/BlitzMax Beginners Area/local myInt:integer=myString$ ?
| ||
I might be overseeing something obvious but I cannot find a Val() operator in BMax. I want to take a string value, such as year:string="2005" and make it equal an integer value yearInt:integer=2005. For some reason I cannot do this (using Mac demo 1.120. Have I been silly? |
| ||
Not sure I fully understand but isn't it... year:string="2005" yearint:int=int(year) |
| ||
Ah, removing the line completely results in the same error. I think i've got a permissions error on the drive somewhere...Building mrcCalender Compiling:mrcCalender.bmx sh: line 1: as: command not found Build Error: Failed to assemble /Users/brose/Dev/mrcCalender/.bmx/mrcCalender.bmx.gui.debug.macos.s Process complete If I goto the package contents of the .debug all i've got is the plist and the icns file. I am learning to loath MacOSX and it's worst of WinXP & Unix approach... |
| ||
XTools wanted reinstalling. All fixed :) The ease of use platform indeed... |
| ||
If you really need explicit conversion, there is a toInt() method on String. |
| ||
Is there a way to find out if a string *can* be converted to an Int? "B".toInt() gives zero, which is no good if zero is a valid value aswell. |
| ||
something like:Function canInt:Int(val:String) For Local i:Int = 0 To 9 If Asc(val[..1]) = 48+i Then Return True Next Return False End Function |
| ||
Hmm, wouldn't that give a false positive for something like "221B Baker Street"? Also, it wouldn't support negative numbers (as far as I can tell). |
| ||
Function ReturnNum:Byte(S:String) If S = "" Then Return False For Local index:Int = 97 To 122 If Lower(S).Find(Chr(index)) <> -1 Then Return False EndIf Next Return True End Function I'm using this to check if a string has only numbers in it or not, maybe this helps. |
| ||
Hmm, wouldn't that give a false positive for something like "221B Baker Street"? Also, it wouldn't support negative numbers (as far as I can tell). It would allow 221B to be converted because 221B can be (BMax will convert as much as it can of the string). It now supports negative numbers as well. Local s:String = "-10g4dsd" Print canInt(s) Print Int(s) Function canInt:Int(val:String) For Local i:Int = 0 To 9 If (Asc(val[..1]) = 48+i) Or ((val[..1] = "-") And Asc(val[1..2]) = 48+i) Then Return True Next Return False End Function |