local myInt:integer=myString$ ?

BlitzMax Forums/BlitzMax Beginners Area/local myInt:integer=myString$ ?

Banshee(Posted 2005) [#1]
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?


tonyg(Posted 2005) [#2]
Not sure I fully understand but isn't it...
year:string="2005"
yearint:int=int(year)


Banshee(Posted 2005) [#3]
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...


Banshee(Posted 2005) [#4]
XTools wanted reinstalling. All fixed :)

The ease of use platform indeed...


FlameDuck(Posted 2005) [#5]
If you really need explicit conversion, there is a toInt() method on String.


taxlerendiosk(Posted 2005) [#6]
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.


Perturbatio(Posted 2005) [#7]
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



taxlerendiosk(Posted 2005) [#8]
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).


klepto2(Posted 2005) [#9]
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.


Perturbatio(Posted 2005) [#10]
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