|
Post by bluatigro on Apr 1, 2020 10:59:01 GMT
test this please
and/or report mistakes
end function isNumber( x$ ) nr$ ="-0123456789e." x$ = lower$( x$ ) fl = 1 for i = 0 to 255 if not( instr( nr$ , chr$( i ) ) ) then if instr( x$ , chr$( i ) ) then fl = 0 end if next i if fl then t = 0 for i = 1 to len( x$ ) then if mid$( x$ , i , 1 ) = "e"then t = t + 1 next i if t = 0 or t = 1 then t = 0 for i = 1 to len( x$ ) then if mid$( x$ , i , 1 ) = "."then t = t + 1 next i if t = 0 or t = 1 then if instr( x$ , "." ) > instr( x$ , "e" ) then fl = 0 else fl = 0 end if else fl = 0 end if end if isNumber = fl end function
|
|
|
Post by tsh73 on Apr 1, 2020 13:47:11 GMT
Here's test harness from old JB contest about writing "isNumber" function. BTW I had to comment two THEN in FOR lines - what was it?
data "0", "0.0", "1237", "1728979873987543687681", "5783.23490908654798729" data "5e46", " -23", "-432.433", "76e-23", "-1.13e-32.2", "abc", "0.1" data "", "34.2w", "12e13e14", "1.2e345678", "END"
while n$ <> "END" read n$ print n$, isNumber(n$) wend
end
function isNumber( x$ ) nr$ ="-0123456789e." x$ = lower$( x$ ) fl = 1 for i = 0 to 255 if not( instr( nr$ , chr$( i ) ) ) then if instr( x$ , chr$( i ) ) then fl = 0 end if next i if fl then t = 0 for i = 1 to len( x$ ) 'then if mid$( x$ , i , 1 ) = "e"then t = t + 1 next i if t = 0 or t = 1 then t = 0 for i = 1 to len( x$ ) 'then if mid$( x$ , i , 1 ) = "."then t = t + 1 next i if t = 0 or t = 1 then if instr( x$ , "." ) > instr( x$ , "e" ) then fl = 0 else fl = 0 end if else fl = 0 end if end if isNumber = fl end function
|
|