Jump to content

Determine if a string is numeric: Difference between revisions

Determine if a string is numeric en True BASIC
m (added whitespace.)
(Determine if a string is numeric en True BASIC)
Line 4,187:
" $a" isNumeric . ( succeeds, because $ is a valid override prefix )
( denoting that the following character is a hexadecimal number )</lang>
 
 
=={{header|True BASIC}}==
{{trans|RapidQ}}
<lang basic>
DECLARE FUNCTION isnumeric$
 
LET true$ = "True"
LET false$ = "False"
LET s$ = "-152.34"
PRINT s$, " => "; isnumeric$(s$)
LET s$ = "1234.056789"
PRINT s$, " => "; isnumeric$(s$)
LET s$ = "1234.56"
PRINT s$, " => "; isnumeric$(s$)
LET s$ = "021101"
PRINT s$, " => "; isnumeric$(s$)
LET s$ = "Dog"
PRINT s$, " => "; isnumeric$(s$)
LET s$ = "Bad125"
PRINT s$, " => "; isnumeric$(s$)
LET s$ = "-0177"
PRINT s$, " => "; isnumeric$(s$)
LET s$ = "+123abcd.ef"
PRINT s$, " => "; isnumeric$(s$)
LET s$ = "54321"
PRINT s$, " => "; isnumeric$(s$)
LET s$ = "123xyz"
PRINT s$, " => "; isnumeric$(s$)
LET s$ = "xyz"
PRINT s$, " => "; isnumeric$(s$)
FUNCTION isnumeric$(s$)
LET optchar$ = ""
IF len(s$) = 0 then
LET isnumeric$ = false$
EXIT FUNCTION
END IF
IF pos(s$,"+") > 1 then
LET isnumeric$ = false$
EXIT FUNCTION
END IF
IF pos(s$,"-") > 1 then
LET isnumeric$ = false$
EXIT FUNCTION
END IF
LET ndex = 0
FOR i = 1 to len(s$)
SELECT CASE ord((s$)[i:i+1-1][1:1])
CASE 43 !+
CASE 45 !-
CASE 46 !.
IF ndex = 1 then
LET isnumeric$ = false$
EXIT FUNCTION
END IF
LET ndex = 1
CASE 48 to 57 !0 a 9
CASE else
IF pos(optchar$,((s$)[i:i+1-1])) = 0 then
LET isnumeric$ = false$
EXIT FUNCTION
END IF
END SELECT
NEXT i
LET isnumeric$ = true$
END FUNCTION
END
</lang>
 
 
=={{header|UNIX Shell}}==
2,170

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.