how can i check if a string is numeric

Production I.
Mannheim,

Nov 17, 2016
2 Posts

0  |  0  

Re: how can i check if a string is numeric

hi,
i want to check if string ist numeric
i have try with procedure val with base 10, but  i have the problem with this call val("123abc", 10).
i want that convert "123abc" to numeric causes  a error.
how can i check if all chars of string are numeric ? i think convert sring to char array and check every char if it in the interval 0-9

thanks in advance
youssef

DrATEasy (Ron Y.)
Mission Viejo, CA

Nov 17, 2016
358 Posts

0  |  0  

Re: how can i check if a string is numeric

procedure IsValidInteger(s: Val String) : Long
iLast : Long
c:Char
{
iLast=Len(s)-1
for i=0 to iLast
    c=s[i]
    if c<'0' and c>'9' then  return False
next

return  True
}

You can change the procedure also to return the last numeric character or enhance to support floating point.

Ronnie

Solution Available
Production I.
Mannheim,

Nov 17, 2016
2 Posts

1  |  0  

Re: how can i check if a string is numeric

Hi Ronnie,
thank you for the quiqly response.
in the if statement should "or" instead of "and" used and i have a check added if the string is empty.
that works now

iLast = Len(s) - 1
if iLast = -1
    ! empty string
    return False
endif
for lCounter=0 to iLast
    c=s[lCounter]
    if c<'0' or c>'9' then  return False
next

return  True

DrATEasy (Ron Y.)
Mission Viejo, CA

Nov 18, 2016
358 Posts

0  |  0  

Re: how can i check if a string is numeric

Great!



Please Note
You need to have a M@GIC account to participate in the Forums.
Not yet registered on our website? Click here to register today!

All content, information and opinions presented on the Marvin Test Solutions User Forums are those of the authors of the posts and messages and not Marvin Test Solutions'. All attachments and files are downloaded at your own risk. [Read More]