For example, if I debug typeof ("test") the result is a String.
View result http://jsfiddle.net/falsam/xg3acvqs/
With PureBasic, it is not possible. It must pass a parameter with a datatype.
This short code is a workaround.
Code: Select all
; GetTypeOf(Value)
; Contributor falsam
;
; PB 4.31 -> 4.40
;
Procedure _GetTypeOf(numstr.s)
Protected Result, Pattern.s = "^[-+]?[0-9]*\.?[0-9]+$"
Protected RegEx = CreateRegularExpression(#PB_Any, Pattern)
If RegEx
Result = MatchRegularExpression(RegEx, numstr)
FreeRegularExpression(RegEx)
If result
If CountString(numstr, ".") = 1
ProcedureReturn #PB_Float
Else
ProcedureReturn #PB_Integer
EndIf
Else
ProcedureReturn #PB_String
EndIf
EndIf
EndProcedure
Macro Quote
""
EndMacro
Macro GetTypeOf(Value=)
_GetTypeOf(Quote + Value + Quote)
EndMacro
Debug GetTypeOf("test") ;String
Debug GetTypeOf("10") ;Integer
Debug GetTypeOf("10.10");Float
Debug GetTypeOf(10) ;Integer
Debug GetTypeof(10.10) ;Float
Debug GetTypeof(-10.10) ;Float