Recent

Author Topic: Checking for number or not  (Read 1202 times)

stab

  • Full Member
  • ***
  • Posts: 237
Checking for number or not
« on: March 19, 2025, 03:12:40 pm »
Hi,

Is there some kind of function like IsANumber to use when reading data from a list containing a range of numbers delimited by a nonNumber? %)

paule32

  • Sr. Member
  • ****
  • Posts: 402
Re: Checking for number or not
« Reply #1 on: March 19, 2025, 03:29:18 pm »
Try this Code:

Code: Pascal  [Select][+][-]
  1. function IsNum(const S: string): Boolean;
  2. var
  3.   I: Integer;
  4. begin
  5.   Result := (S <> '');
  6.   for I := 1 to Length(S) do
  7.   begin
  8.     if not (S[I] in ['0'..'9']) then
  9.     begin
  10.       Result := False;
  11.       Exit;
  12.     end;
  13.   end;
  14. end;

HTH - Hope This Helps
MS-IIS - Internet Information Server, Apache, PHP/HTML/CSS, MinGW-32/64 MSys2 GNU C/C++ 13 (-stdc++20), FPC 3.2.2
A Friend in need, is a Friend indeed.

stab

  • Full Member
  • ***
  • Posts: 237
Re: Checking for number or not
« Reply #2 on: March 19, 2025, 03:40:29 pm »
Thank you, but it doesn't work.

I'm using TAContour for contouring a lot of black areas in an image and get¨the result in a TLineSerie where all polygones are separated with some kind of nonNumber. When trying to use your code I get following error when compiling:
Error: Incompatible type for arg no. 1: Got "Double", expected "AnsiString"

alpine

  • Hero Member
  • *****
  • Posts: 1376
Re: Checking for number or not
« Reply #3 on: March 19, 2025, 03:44:30 pm »
Hi,

Is there some kind of function like IsANumber to use when reading data from a list containing a range of numbers delimited by a nonNumber? %)
Please give an example of such a list. IsANumber as opposed to nonNumber won't give you a chance to separate the test sub-strings between the delimiters (non-number) at the first place.   %)

@paule32
The Val() procedure is suitable for that
"I'm sorry Dave, I'm afraid I can't do that."
—HAL 9000

Nimbus

  • New Member
  • *
  • Posts: 29

jamie

  • Hero Member
  • *****
  • Posts: 6874
Re: Checking for number or not
« Reply #5 on: March 19, 2025, 03:51:50 pm »
Thank you, but it doesn't work.

I'm using TAContour for contouring a lot of black areas in an image and get¨the result in a TLineSerie where all polygones are separated with some kind of nonNumber. When trying to use your code I get following error when compiling:
Error: Incompatible type for arg no. 1: Got "Double", expected "AnsiString"

Then you are not parsing a string but a double which is a binary image of a floating point
The only true wisdom is knowing you know nothing

stab

  • Full Member
  • ***
  • Posts: 237
Re: Checking for number or not
« Reply #6 on: March 19, 2025, 03:52:33 pm »
Thanks to your all and especially to Nimbus. Your tip made it :D

Bart

  • Hero Member
  • *****
  • Posts: 5554
    • Bart en Mariska's Webstek
Re: Checking for number or not
« Reply #7 on: March 19, 2025, 10:05:18 pm »
My IsNumeric in my fsisillystuff.pp unit can parse string representing (big)integers, including strings in binary, octal, hexadecimal, roman notation and (big)floating point numbers.
Currently it cannot parse complex numbers though.

Bart

MarkMLl

  • Hero Member
  • *****
  • Posts: 8364
Re: Checking for number or not
« Reply #8 on: March 20, 2025, 08:56:23 pm »
I'm troubled by this thread. IsNaN() takes a real- not a string- as a parameter and looks for the specific NaN bit pattern, which begs the question of what's being used for parsing that returns a NaN if it doesn't like what it sees.

There's a whole lot of TryXXX() functions for conditionally parsing strings, for example https://www.freepascal.org/docs-html/current/rtl/sysutils/trystrtofloat.html and https://www.freepascal.org/docs-html/current/rtl/sysutils/trystrtoint.html .

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

Nimbus

  • New Member
  • *
  • Posts: 29
Re: Checking for number or not
« Reply #9 on: March 20, 2025, 09:27:51 pm »
Guys. The TS never said he needed to parse a string. He's plotting a Chart with TLineSeries, what he's got is an array of floating points. Some of which apparently are Not a Number in the sense of IEEE 754 NaN - therefore he needed a method to check against those values.

alpine

  • Hero Member
  • *****
  • Posts: 1376
Re: Checking for number or not
« Reply #10 on: March 21, 2025, 09:25:55 am »
Guys. The TS never said he needed to parse a string. He's plotting a Chart with TLineSeries, what he's got is an array of floating points. Some of which apparently are Not a Number in the sense of IEEE 754 NaN - therefore he needed a method to check against those values.
Yeah. But he mentioned TLineSeries latter in his second post and shortly before I posted my request for clarification. The initial post was confusing and rather logically contradictory.

Nevermind, It seems he got his question answered, which is what's important.
"I'm sorry Dave, I'm afraid I can't do that."
—HAL 9000

paule32

  • Sr. Member
  • ****
  • Posts: 402
Re: Checking for number or not
« Reply #11 on: March 21, 2025, 01:52:07 pm »
what is the meaning of: TS ?

TS = Terminal Server
TS = Topic Starter
TS = Toast Side
?
MS-IIS - Internet Information Server, Apache, PHP/HTML/CSS, MinGW-32/64 MSys2 GNU C/C++ 13 (-stdc++20), FPC 3.2.2
A Friend in need, is a Friend indeed.

wp

  • Hero Member
  • *****
  • Posts: 12761
Re: Checking for number or not
« Reply #12 on: March 21, 2025, 03:03:28 pm »
TS = thread starter

 

TinyPortal © 2005-2018