Discussion:
magnitude comparison of numbers and letters
(too old to reply)
Tom Del Rosso
2024-03-13 03:52:24 UTC
Permalink
I want to know if a variable equals a number, with no letters in it.

I know you can check with FOR /F "DELIMS=0123456789" but it looks like a
simpler way is just to test like so:

if A gtr 1000 echo That's a letter

or

if 4A gtr 1000 echo That contains a letter

This assumes that I know what the highest possible number will be, so if
the first value is a number it will always be less.

Is there a problem in doing this?
--
Defund the Thought Police
R.Wieser
2024-03-13 08:19:21 UTC
Permalink
Tom,
Post by Tom Del Rosso
if A gtr 1000 echo That's a letter
or
if 4A gtr 1000 echo That contains a letter
This assumes that I know what the highest possible number will be, so if
the first value is a number it will always be less.
Is there a problem in doing this?
Yes. A quick test just now shows that both of the above cause string
comparision.

And that means that any ASCII character below "0" will not be recognised as
a letter. Just try "if $ gtr 1000"

IOW, you will need an "if lower than 0 or larger than 9" check - and hope
that any non-digit characters, when hidden inside the value, will not modify
that value.

Regards,
Rudy Wieser
Zaidy036
2024-03-13 17:44:52 UTC
Permalink
Post by R.Wieser
Tom,
Post by Tom Del Rosso
if A gtr 1000 echo That's a letter
or
if 4A gtr 1000 echo That contains a letter
This assumes that I know what the highest possible number will be, so if
the first value is a number it will always be less.
Is there a problem in doing this?
Yes. A quick test just now shows that both of the above cause string
comparision.
And that means that any ASCII character below "0" will not be recognised as
a letter. Just try "if $ gtr 1000"
IOW, you will need an "if lower than 0 or larger than 9" check - and hope
that any non-digit characters, when hidden inside the value, will not modify
that value.
Regards,
Rudy Wieser
<https://superuser.com/questions/1065531/filter-only-numbers-0-9-in-output-in-classic-windows-cmd>
R.Wieser
2024-03-13 18:16:46 UTC
Permalink
Zaidy036,
Post by Zaidy036
<https://superuser.com/questions/1065531/filter-only-numbers-0-9-in-output-in-classic-windows-cmd>
That doesn't match the OPs question I'm afraid (also, I'm not the OP).

Regards,
Rudy Wieser
Kenny McCormack
2024-03-13 18:33:42 UTC
Permalink
In article <ussqiu$12vg2$***@dont-email.me>, R.Wieser <***@is.invalid> wrote:
...
Post by R.Wieser
That doesn't match the OPs question I'm afraid (also, I'm not the OP).
You wouldn't be referring to "the OP" in the third person if you were,
would you?
--
You are again heaping damnation upon your own head by your statements.

- Rick C Hodgin -
R.Wieser
2024-03-13 19:05:32 UTC
Permalink
Kenny,
Post by Kenny McCormack
You wouldn't be referring to "the OP" in the third person if you
were, would you?
Indeed, I would not.

But as Zaidy036 didn't get that I'm not the OP - or the question for that
matter - I wanted to make sure the message got thru.

I didn't think I needed to explain that to an obviously observant reader
like yourself ...

Regards,
Rudy Wieser

Loading...